-
Notifications
You must be signed in to change notification settings - Fork 3
/
azure-pipelines.yml
232 lines (215 loc) · 9.58 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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
# https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/?view=vsts
# https://docs.microsoft.com/en-us/azure/devops/pipelines/yaml-schema?view=azure-devops&tabs=schema
# https://docs.microsoft.com/en-us/azure/devops/pipelines/process/expressions?view=azure-devops
variables:
solution: '**/*.sln'
buildConfiguration: 'Release'
publishWebApp: true
publishFunctionApp: false
publishWorkerService: false
publishArtifacts: true
nuGetPackages: '**/Foundation*.csproj'
nuGetPush: true
nuGetFeed: '164130b9-cbc9-46a4-85b0-3bd84e74894d/151703fd-0d42-49db-a7a3-d22198435821' # https://vip32.pkgs.visualstudio.com/Naos/_packaging/naos/nuget/v3/index.json
nuGetFeedType: 'internal' # 'external'
deployEnabled: false
deployAzureSubscription: 'Naos 22463ad3-c6d2-4e7e-911d-c50474250fa0' # https://docs.microsoft.com/en-us/azure/devops/pipelines/process/resources?view=azure-devops#troubleshooting-authorization-for-a-yaml-pipeline
deployWebAppName: 'unknown'
deployFunctionAppName: 'unknown'
vmImage: 'windows-latest' # https://docs.microsoft.com/en-us/azure/devops/pipelines/agents/hosted?view=azure-devops&tabs=yaml#use-a-microsoft-hosted-agent
group: vars # azure pipelines variable group https://docs.microsoft.com/en-us/azure/devops/pipelines/library/variable-groups?view=azdevops&tabs=yaml
trigger:
- master
- develop
- hotfix/*
- release/*
- feature/*
- refs/tags/v*
resources:
- repo: self
fetchDepth: 1
stages:
- stage: Build
displayName: Build stage
jobs:
- job: Build
displayName: Build job
pool:
vmImage: $(vmImage)
steps:
- task: GitVersion@5 # alternative https://github.com/adamralph/minver
displayName: Apply git version
- task: UseDotNet@2
displayName: Install dotnet SDK
inputs:
version: '3.1.x'
packageType: sdk
- task: DotNetCoreCLI@2 # https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/build/dotnet-core?view=azure-devops#restore-nuget-packages
displayName: Restore project dependencies
inputs:
command: restore
projects: '**/*.csproj'
verbosityRestore: Normal
feedsToUse: 'config'
nugetConfigPath: 'nuget.config'
- task: DotNetCoreCLI@2
displayName: Build projects
inputs:
projects: '$(solution)'
arguments: '--configuration $(buildConfiguration) --no-restore /p:Version=$(GitVersion.NuGetVersionV2);AssemblyVersion=$(GitVersion.AssemblySemVer);FileVersion=$(GitVersion.AssemblySemVer);InformationalVersion=$(GitVersion.InformationalVersion)'
# assembly versioning: https://pleasereleaseme.net/versioning-net-core-assemblies-in-azure-devops-isnt-straightforward-and-probably-wont-be-in-other-ci-cd-tools-either/
- task: DotNetCoreCLI@2
displayName: Run unit tests
enabled: false
env:
'naos__secrets__vault__clientId': $(key-vault-clientId) # from vars group
'naos__secrets__vault__clientSecret': $(key-vault-clientSecret) # from vars group
'naos__secrets__vault__name': 'naos'
inputs:
command: test
projects: '**/*[Tt]ests/*UnitTests.csproj'
arguments: '--configuration $(buildConfiguration) --no-restore --no-build'
# arguments: '/p:Configuration=$(buildConfiguration) /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:CoverletOutput=$(Build.ArtifactStagingDirectory)/coverage.xml' # https://github.com/tonerdo/coverlet
- task: Bash@3
displayName: "codecov upload" # https://docs.codecov.io/docs/about-the-codecov-bash-uploader
enabled: false
inputs:
targetType: "filePath"
filePath: "./tests/CodecovUploader.sh"
workingDirectory: $(Build.ArtifactStagingDirectory)
arguments: "-f coverage.xml -t b4c5d4f3-0f3a-470e-9d5d-4c63cba2e611 -B $(Build.SourceBranchName) -C $(Build.SourceVersion) -b $(Build.BuildNumber)"
- task: PublishPipelineArtifact@0 # https://docs.microsoft.com/en-us/azure/devops/pipelines/artifacts/pipeline-artifacts?view=azure-devops&tabs=yaml
displayName: Publish sources
enabled: true
inputs:
artifactName: 'sources'
targetPath: '$(Build.SourcesDirectory)'
- task: DotNetCoreCLI@2
displayName: Publish worker service
enabled: true
condition: and(succeeded(), eq(variables['publishWorkerService'], 'true'))
inputs:
command: publish
publishWebProjects: False
projects: '**/Application.WorkerService.csproj'
arguments: '--configuration $(buildConfiguration) --no-restore --no-build --output $(System.DefaultWorkingDirectory)/artifacts'
# self contained https://timheuer.com/blog/archive/2019/10/03/deploy-aspnet-core-applications-using-self-contained-dotnet-core.aspx?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+timheuer+%28Method+~+of+~+failed+by+Tim+Heuer%29
zipAfterPublish: True
- task: DotNetCoreCLI@2
displayName: Publish web app
enabled: true
condition: and(succeeded(), eq(variables['publishWebApp'], 'true'))
inputs:
command: publish
publishWebProjects: True
projects: '**/Application.Web.csproj'
arguments: '--configuration $(buildConfiguration) --no-restore --no-build --output $(System.DefaultWorkingDirectory)/artifacts'
# self contained https://timheuer.com/blog/archive/2019/10/03/deploy-aspnet-core-applications-using-self-contained-dotnet-core.aspx?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+timheuer+%28Method+~+of+~+failed+by+Tim+Heuer%29
zipAfterPublish: True
- task: DotNetCoreCLI@2
displayName: Publish function app
enabled: true
condition: and(succeeded(), eq(variables['publishFunctionApp'], 'true'))
inputs:
command: publish
publishWebProjects: False
projects: '**/Application.Functions.csproj'
arguments: '--configuration $(buildConfiguration) --no-restore --no-build --output $(System.DefaultWorkingDirectory)/artifacts'
# self contained https://timheuer.com/blog/archive/2019/10/03/deploy-aspnet-core-applications-using-self-contained-dotnet-core.aspx?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+timheuer+%28Method+~+of+~+failed+by+Tim+Heuer%29
zipAfterPublish: True
- task: PublishPipelineArtifact@0 # https://docs.microsoft.com/en-us/azure/devops/pipelines/artifacts/pipeline-artifacts?view=azure-devops&tabs=yaml
displayName: Publish pipeline artifacts
enabled: true
condition: and(succeeded(), eq(variables['publishArtifacts'], 'true'))
inputs:
artifactName: 'artifacts'
targetPath: '$(System.DefaultWorkingDirectory)/artifacts'
- task: DotNetCoreCLI@2 # https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/build/dotnet-core?view=azure-devops#pack-nuget-packages
displayName: Package nugets
enabled: true
condition: |
and
(
eq(variables['nuGetPush'], 'true'),
eq(variables['Build.SourceBranch'], 'refs/heads/master')
)
inputs:
command: pack
configuration: $(buildConfiguration)
packagesToPack: $(nuGetPackages)
nobuild: true
packDirectory: '$(System.DefaultWorkingDirectory)/packages'
buildProperties: 'Version=$(GitVersion.NuGetVersion)'
verbosityPack: Normal
#
- task: DotNetCoreCLI@2 # https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/build/dotnet-core?view=azure-devops#push-nuget-packages
displayName: Push nugets # TODO: github package repository https://help.github.com/en/articles/about-github-package-registry#supported-clients-and-formats
enabled: true
condition: |
and
(
succeeded(),
eq(variables['nuGetPush'], 'true'),
eq(variables['Build.SourceBranch'], 'refs/heads/master')
)
inputs:
command: push
packagesToPush: '$(System.DefaultWorkingDirectory)/packages/*.nupkg'
nobuild: true
publishVstsFeed: $(nuGetFeed)
nuGetFeedType: $(nuGetFeedType)
allowPackageConflicts: true
- stage: DeployDev
displayName: Deploy stage (dev)
condition: |
and
(
succeeded(),
eq(variables['deployEnabled'], 'true'),
eq(variables['Build.SourceBranch'], 'refs/heads/develop')
)
jobs:
- template: azure-pipelines-deploy.yml
parameters:
environment: 'dev'
deployWebApp: true # $(publishWebApp)
deployFunctionApp: false # $(publishFunctionApp)
azureSubscription: $(deployAzureSubscription)
appName: $(deployWebAppName)
functionAppName: $(deployFunctionAppName)
- stage: DeployQas
displayName: Deploy stage (qas)
condition: |
and
(
succeeded(),
eq(variables['deployEnabled'], 'true'),
eq(variables['Build.SourceBranch'], 'refs/heads/master')
)
jobs:
- template: azure-pipelines-deploy.yml
parameters:
environment: 'qas'
deployWebApp: true # $(publishWebApp)
deployFunctionApp: false # $(publishFunctionApp)
azureSubscription: $(deployAzureSubscription)
appName: $(deployWebAppName)
functionAppName: $(deployFunctionAppName)
- stage: DeployPro
displayName: Deploy stage (pro)
condition: |
and
(
succeeded(),
eq(variables['deployEnabled'], 'true'),
eq(variables['Build.SourceBranch'], 'refs/heads/master')
)
jobs:
- template: azure-pipelines-deploy.yml
parameters:
environment: 'pro'
deployWebApp: true # $(publishWebApp)
deployFunctionApp: false # $(publishFunctionApp)
azureSubscription: $(deployAzureSubscription)
appName: $(deployWebAppName)
functionAppName: $(deployFunctionAppName)