Skip to content

Commit 5a68747

Browse files
authored
ci: provision environments for pipelines (#75)
1 parent 90c7f76 commit 5a68747

File tree

5 files changed

+307
-115
lines changed

5 files changed

+307
-115
lines changed

azure-pipelines-pull-request.yml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
name: $(GITVERSION_FullSemVer)
2+
23
trigger: none
4+
35
pr:
46
- master
7+
58
pool:
6-
vmImage: 'windows-latest'
9+
vmImage: windows-latest
10+
711
stages:
8-
- stage: BuildAndTest
9-
displayName: Build and Test
10-
jobs:
11-
- template: templates/build-and-test-job.yml
12+
- template: templates/build-and-test-stages.yml
13+
parameters:
14+
environmentIdentifier: $[ coalesce(variables['System.PullRequest.PullRequestNumber'], variables['Build.BuildId']) ]
15+
environmentDisplayName: Package Deployer Template - PR
16+
environmentDomainName: pdt-pr

azure-pipelines.yml

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,25 @@
11
name: $(GITVERSION_FullSemVer)
2+
23
trigger:
34
batch: true
45
branches:
56
include:
67
- master
8+
79
pr: none
10+
811
pool:
9-
vmImage: 'windows-latest'
10-
variables:
11-
- name: GitVersion.SemVer
12-
value: ''
13-
- name: solution
14-
value: '**/*.sln'
15-
- name: buildPlatform
16-
value: 'anycpu'
17-
- name: buildConfiguration
18-
value: 'Release'
12+
vmImage: windows-latest
13+
1914
stages:
20-
- stage: BuildAndTest
21-
displayName: Build and Test
22-
jobs:
23-
- template: templates/build-and-test-job.yml
15+
- template: templates/build-and-test-stages.yml
16+
parameters:
17+
environmentIdentifier: $(Build.BuildId)
18+
environmentDisplayName: Package Deployer Template - CI
19+
environmentDomainName: pdt-ci
2420
- stage: Publish
2521
displayName: Publish
22+
dependsOn: ManualValidation
2623
jobs:
2724
- job: PublishJob
2825
displayName: Publish
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#
2+
# New-PowerAppFlowConnection.ps1
3+
#
4+
[CmdletBinding()]
5+
param (
6+
[string]
7+
[Parameter(Mandatory = $true)]
8+
$Username,
9+
[securestring]
10+
[Parameter(Mandatory = $true)]
11+
$Password,
12+
[Parameter(Mandatory = $true)]
13+
[string]
14+
$EnvironmentName,
15+
[Parameter(Mandatory = $true)]
16+
[string]
17+
$Region,
18+
[Parameter(Mandatory = $true)]
19+
[string]
20+
$Connector,
21+
[Parameter(Mandatory = $false)]
22+
[hashtable]
23+
$ConnectionParameters = @{},
24+
[string]
25+
[parameter(Mandatory = $false)]
26+
$DisplayName,
27+
[string]
28+
[Parameter(Mandatory = $false)]
29+
$OutputVariable
30+
)
31+
32+
$ErrorActionPreference = 'Stop'
33+
34+
Install-Module -Name Microsoft.PowerApps.Administration.PowerShell -Force -Scope CurrentUser -AllowClobber
35+
36+
Write-Host "Authenticating as $Username."
37+
Add-PowerAppsAccount -Username $Username -Password $Password
38+
39+
if (!$ConnectionId) {
40+
$ConnectionId = [Guid]::NewGuid().ToString("N")
41+
}
42+
43+
$body = @{
44+
properties = @{
45+
environment = @{
46+
name = "$EnvironmentName"
47+
}
48+
connectionParameters = $ConnectionParameters
49+
displayName = $DisplayName
50+
}
51+
}
52+
53+
Write-Host "Creating $Connector connection with ID $ConnectionId on environment $EnvironmentName with $($ConnectionParameters.connectionString)"
54+
55+
$result = InvokeApi `
56+
-Method PUT `
57+
-Route "https://$Region.api.powerapps.com/providers/Microsoft.PowerApps/apis/$Connector/connections/$($ConnectionId)?api-version=2021-02-01&`$filter=environment eq '$EnvironmentName'" `
58+
-Body $body `
59+
-ThrowOnFailure
60+
61+
Write-Host "Connection $($result.name) created."
62+
63+
if ($OutputVariable) {
64+
Write-Host "Setting $OutputVariable variable to $($result.name)."
65+
Write-Host "##vso[task.setvariable variable=$OutputVariable]$($result.name)"
66+
}

templates/build-and-test-job.yml

Lines changed: 115 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -1,97 +1,116 @@
1-
jobs:
2-
- job: BuildAndTestJob
3-
displayName: Build and Test
4-
variables:
5-
- name: GitVersion.SemVer
6-
value: ''
7-
- name: solution
8-
value: '**/*.sln'
9-
- name: buildPlatform
10-
value: 'anycpu'
11-
- name: buildConfiguration
12-
value: 'Release'
13-
- group: Cap Dev - CI
14-
steps:
15-
16-
- task: gitversion/setup@0
17-
displayName: Install GitVersion
18-
inputs:
19-
versionSpec: '5.x'
20-
21-
- task: gitversion/execute@0
22-
displayName: Execute GitVersion
23-
inputs:
24-
useConfigFile: true
25-
configFilePath: '$(Build.SourcesDirectory)\GitVersion.yml'
26-
updateAssemblyInfo: false
27-
28-
- pwsh: Write-Host "##vso[task.setvariable variable=SemVer;isOutput=true]$(GitVersion.SemVer)"
29-
name: OutputSemVerTask
30-
displayName: Output SemVer
31-
32-
- task: DotNetCoreCLI@2
33-
displayName: Restore NuGet packages
34-
inputs:
35-
command: restore
36-
projects: '**/*.csproj'
37-
38-
- task: SonarCloudPrepare@1
39-
displayName: Prepare SonarCloud
40-
inputs:
41-
SonarCloud: 'SonarCloud'
42-
organization: 'capgemini-1'
43-
scannerMode: 'MSBuild'
44-
projectKey: 'Capgemini_xrm-packagedeployer'
45-
projectName: 'xrm-packagedeployer'
46-
projectVersion: '$(GitVersion.SemVer)'
47-
extraProperties: |
48-
sonar.exclusions=**\*.css
1+
parameters:
2+
- name: environmentUrl
3+
displayName: Environment URL
4+
type: string
5+
- name: environmentName
6+
displayName: environmentName
7+
type: string
8+
- name: username
9+
displayName: Username
10+
type: string
11+
- name: password
12+
displayName: Password
13+
type: string
4914

50-
- task: VSBuild@1
51-
displayName: Build solution
52-
inputs:
53-
solution: '$(solution)'
54-
platform: '$(buildPlatform)'
55-
configuration: '$(buildConfiguration)'
56-
57-
- task: VSTest@2
58-
displayName: Run tests
59-
env:
60-
CAPGEMINI_PACKAGE_DEPLOYER_TESTS_URL: $(URL)
61-
CAPGEMINI_PACKAGE_DEPLOYER_TESTS_USERNAME: $(User ADO Integration Username)
62-
CAPGEMINI_PACKAGE_DEPLOYER_TESTS_PASSWORD: $(User ADO Integration Password)
63-
inputs:
64-
codeCoverageEnabled: true
65-
platform: '$(buildPlatform)'
66-
configuration: '$(buildConfiguration)'
67-
testAssemblyVer2: '**\*Tests.dll'
68-
searchFolder: tests
69-
70-
- task: SonarCloudAnalyze@1
71-
displayName: Analyse with SonarCloud
72-
73-
- task: SonarCloudPublish@1
74-
displayName: Publish SonarCloud results
75-
inputs:
76-
pollingTimeoutSec: '300'
77-
78-
- task: WhiteSource Bolt@20
79-
displayName: Detect security and licence issues
80-
inputs:
81-
cwd: '$(Build.SourcesDirectory)'
82-
83-
- task: DotNetCoreCLI@2
84-
displayName: Pack NuGet package
85-
inputs:
86-
command: pack
87-
packagesToPack: src\Capgemini.PowerApps.PackageDeployerTemplate\Capgemini.PowerApps.PackageDeployerTemplate.csproj
88-
modifyOutputPath: true
89-
versioningScheme: byEnvVar
90-
versionEnvVar: GitVersion.NuGetVersionV2
91-
includesymbols: false
92-
buildProperties: Configuration=$(buildConfiguration)
93-
packDirectory: $(Build.ArtifactStagingDirectory)/out
94-
95-
- publish: $(Build.ArtifactStagingDirectory)/out
96-
displayName: Publish NuGet artifact
97-
artifact: Capgemini.PowerApps.PackageDeployerTemplate
15+
jobs:
16+
- job: BuildAndTestJob
17+
displayName: Build and Test
18+
variables:
19+
- name: GitVersion.SemVer
20+
value: ''
21+
- name: solution
22+
value: '**/*.sln'
23+
- name: buildPlatform
24+
value: 'anycpu'
25+
- name: buildConfiguration
26+
value: 'Release'
27+
steps:
28+
- task: gitversion/setup@0
29+
displayName: Install GitVersion
30+
inputs:
31+
versionSpec: '5.x'
32+
- task: gitversion/execute@0
33+
displayName: Execute GitVersion
34+
inputs:
35+
useConfigFile: true
36+
configFilePath: '$(Build.SourcesDirectory)\GitVersion.yml'
37+
updateAssemblyInfo: false
38+
- pwsh: Write-Host "##vso[task.setvariable variable=SemVer;isOutput=true]$(GitVersion.SemVer)"
39+
name: OutputSemVerTask
40+
displayName: Output SemVer
41+
- task: DotNetCoreCLI@2
42+
displayName: Restore NuGet packages
43+
inputs:
44+
command: restore
45+
projects: '**/*.csproj'
46+
- task: SonarCloudPrepare@1
47+
displayName: Prepare SonarCloud
48+
inputs:
49+
SonarCloud: 'SonarCloud'
50+
organization: 'capgemini-1'
51+
scannerMode: 'MSBuild'
52+
projectKey: 'Capgemini_xrm-packagedeployer'
53+
projectName: 'xrm-packagedeployer'
54+
projectVersion: '$(GitVersion.SemVer)'
55+
extraProperties: |
56+
sonar.exclusions=**\*.css
57+
- task: VSBuild@1
58+
displayName: Build solution
59+
inputs:
60+
solution: '$(solution)'
61+
platform: '$(buildPlatform)'
62+
configuration: '$(buildConfiguration)'
63+
- task: PowerShell@2
64+
displayName: Create Approvals connection
65+
inputs:
66+
filePath: $(Build.SourcesDirectory)\scripts\New-PowerAppFlowConnection.ps1
67+
arguments: >
68+
-Username ${{ parameters.username }}
69+
-Password (ConvertTo-SecureString -String $env:CONNECTIONOWNER_PASSWORD -AsPlainText -Force)
70+
-EnvironmentName ${{ parameters.environmentName }}
71+
-Region unitedkingdom
72+
-Connector shared_approvals
73+
-ConnectionParameters @{ }
74+
-OutputVariable "TestEnvironment.Connection.Approvals"
75+
targetType: filePath
76+
env:
77+
CONNECTIONOWNER_PASSWORD: ${{ parameters.password }}
78+
- task: VSTest@2
79+
displayName: Run tests
80+
env:
81+
CAPGEMINI_PACKAGE_DEPLOYER_TESTS_URL: ${{ parameters.environmentUrl }}
82+
CAPGEMINI_PACKAGE_DEPLOYER_TESTS_USERNAME: ${{ parameters.username }}
83+
CAPGEMINI_PACKAGE_DEPLOYER_TESTS_PASSWORD: ${{ parameters.password }}
84+
PACKAGEDEPLOYER_SETTINGS_CONNREF_PDT_SHAREDAPPROVALS_D7DCB: $(TestEnvironment.Connection.Approvals)
85+
PACKAGEDEPLOYER_SETTINGS_ENVVAR_PDT_TESTVARIABLE: Any string
86+
PACKAGEDEPLOYER_SETTINGS_CONNBASEURL_pdt_5Fexample-20api: https://anyurl.com
87+
inputs:
88+
codeCoverageEnabled: true
89+
platform: '$(buildPlatform)'
90+
configuration: '$(buildConfiguration)'
91+
testAssemblyVer2: '**\*Tests.dll'
92+
searchFolder: tests
93+
- task: SonarCloudAnalyze@1
94+
displayName: Analyse with SonarCloud
95+
- task: SonarCloudPublish@1
96+
displayName: Publish SonarCloud results
97+
inputs:
98+
pollingTimeoutSec: '300'
99+
- task: WhiteSource Bolt@20
100+
displayName: Detect security and licence issues
101+
inputs:
102+
cwd: '$(Build.SourcesDirectory)'
103+
- task: DotNetCoreCLI@2
104+
displayName: Pack NuGet package
105+
inputs:
106+
command: pack
107+
packagesToPack: src\Capgemini.PowerApps.PackageDeployerTemplate\Capgemini.PowerApps.PackageDeployerTemplate.csproj
108+
modifyOutputPath: true
109+
versioningScheme: byEnvVar
110+
versionEnvVar: GitVersion.NuGetVersionV2
111+
includesymbols: false
112+
buildProperties: Configuration=$(buildConfiguration)
113+
packDirectory: $(Build.ArtifactStagingDirectory)/out
114+
- publish: $(Build.ArtifactStagingDirectory)/out
115+
displayName: Publish NuGet artifact
116+
artifact: Capgemini.PowerApps.PackageDeployerTemplate

0 commit comments

Comments
 (0)