-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathazure-pipelines.yml
181 lines (156 loc) · 5.6 KB
/
azure-pipelines.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# YAML spec:
# https://aka.ms/yaml
name: '$(Date:yyyyMMdd)$(Rev:.r) (#$(BuildID)) $(TeamProject) ($(SourceBranchName))'
variables:
ChocoCIClient.labVMName: 'ChocoCIClient'
ChocoCIClient.labVMUserName: 'ansible'
# ChocoCIClient.labVMPassword: <secret>
ChocoCIClient.ansibleUser: 'ansible-test'
# ChocoCIClient.ansiblePassword: <secret>
collectionArtifactName: 'chocolatey.collection'
Package.Version: 24.6.26
trigger:
batch: true
branches:
include:
- master
tags:
include:
- '*'
pr:
- master
stages:
- stage: Build
displayName: '[Build]'
jobs:
- job: CreateVM
displayName: 'Create Windows VM'
pool:
vmImage: ubuntu-latest
steps:
- task: AzureDevTestLabsCreateVM@3
name: AzureVM
displayName: 'Create Azure Labs VM'
inputs:
azureSubscription: 'Visual Studio Professional Subscription - Joel'
LabId: '/subscriptions/6f2ac189-3b89-4d14-a0af-f5f808633f91/resourceGroups/choco-ci/providers/Microsoft.DevTestLab/labs/ChocoAnsibleLab'
VirtualMachineName: '$(ChocoCIClient.labVMName)'
TemplateFile: 'build/azure/client-template.json'
ParameterOverrides: '-newVMName ''$(ChocoCIClient.labVMName)'' -userName ''$(ChocoCIClient.labVMUserName)'' -password ''$(ChocoCIClient.labVMPassword)'' -Configure_WinRM_hostName ''$(ChocoCIClient.labVMFqdn)'''
- task: AzurePowerShell@4
displayName: 'VM Setup'
name: AzVmConfig
inputs:
azureSubscription: 'Visual Studio Professional Subscription - Joel'
ScriptPath: 'build/azure/Set-AzLabVMParams.ps1'
ScriptArguments: '-LabVMId $(AzureVM.labVmId) -Username $(ChocoCIClient.ansibleUser) -Secret $(ChocoCIClient.ansiblePassword)'
azurePowerShellVersion: LatestVersion
- job: Tests
displayName: 'Create & Test Collection'
dependsOn: CreateVM
pool:
vmImage: ubuntu-latest
variables:
labVmFqdn: $[ dependencies.CreateVM.outputs['AzVmConfig.Fqdn'] ]
steps:
- task: Bash@3
displayName: 'Install Dependencies'
inputs:
targetType: filePath
filePath: ./build/dependencies.sh
- task: PowerShell@2
displayName: 'Set Package Version'
inputs:
targetType: 'inline'
script: |
$version = if ("$(Build.SourceBranch)" -match '^refs/tags/(?<Tag>.+)') {
# Github version tags usually begin with a "v", but we just want the number
$matches.Tag -replace '^v'
}
else {
"$env:PACKAGE_VERSION-$(Get-Date -Format 'yyyyMMdd')-$(New-Guid)"
}
Write-Host "##vso[task.setvariable variable=Package.Version]$version"
errorActionPreference: 'stop'
failOnStderr: true
pwsh: true
- task: AzureCLI@2
displayName: 'Run Ansible-Test for Collection'
name: TestRun
inputs:
azureSubscription: 'Visual Studio Professional Subscription - Joel'
scriptType: pscore
scriptPath: 'build/Invoke-CollectionTests.ps1'
arguments: '-IsCIBuild -Username $(ChocoCIClient.ansibleUser) -ComputerName $(labVMFqdn) -Secret $(ChocoCIClient.ansiblePassword)'
- task: PublishPipelineArtifact@1
displayName: 'Publish Ansible-Test Output Artifact'
condition: succeededOrFailed()
inputs:
path: '$(System.DefaultWorkingDirectory)/testresults'
artifact: 'Ansible-Test Output Files'
- task: PublishPipelineArtifact@1
displayName: 'Publish Collection Tarball Artifact'
inputs:
path: '$(TestRun.ArtifactPath)'
artifact: '$(collectionArtifactName)'
- task: PublishTestResults@2
displayName: 'Publish JUnit Results'
condition: succeededOrFailed()
inputs:
testResultsFormat: 'JUnit'
searchFolder: '$(System.DefaultWorkingDirectory)/testresults'
testResultsFiles: '**/*.xml'
publishRunAttachments: true
- job: DestroyVM
displayName: 'Destroy Azure Labs VM'
pool:
vmImage: ubuntu-latest
dependsOn:
- CreateVM
- Tests
condition: always()
variables:
labVmId: $[ dependencies.CreateVM.outputs['AzureVM.labVmId'] ]
steps:
- task: AzureDevTestLabsDeleteVM@3
displayName: 'Destroy VM'
inputs:
azureSubscription: 'Visual Studio Professional Subscription - Joel'
LabId: '/subscriptions/6f2ac189-3b89-4d14-a0af-f5f808633f91/resourceGroups/choco-ci/providers/Microsoft.DevTestLab/labs/ChocoAnsibleLab'
LabVmId: '$(labVmId)'
continueOnError: true
- stage: Publish
displayName: '[Publish]'
dependsOn: Build
condition: and(succeeded(), startsWith(variables['Build.SourceBranch'], 'refs/tags/'))
jobs:
- job: Publish
displayName: 'Publish Chocolatey Collection'
pool:
vmImage: ubuntu-latest
steps:
- task: Bash@3
displayName: 'Install Dependencies'
inputs:
targetType: filePath
filePath: ./build/dependencies.sh
- task: DownloadPipelineArtifact@2
displayName: 'Download Tarball Artifact'
inputs:
artifact: '$(collectionArtifactName)'
targetPath: '$(System.DefaultWorkingDirectory)/artifacts/'
- task: PowerShell@2
displayName: 'Publish Chocolatey Collection to Galaxy'
inputs:
targetType: filePath
filePath: ./build/Publish-Collection.ps1
arguments: -ApiKey $(GalaxyApiKey)
pwsh: true
- task: PowerShell@2
enabled: false # pending AH access
displayName: 'Publish Chocolatey Collection to AH'
inputs:
targetType: filePath
filePath: ./build/Publish-Collection.ps1
arguments: -ApiKey $(AHApiKey) -Url $(AHUrl)
pwsh: true