forked from HoussemDellai/WebAppWithDatabaseDemo
-
Notifications
You must be signed in to change notification settings - Fork 2
/
azure-pipelines.yml
333 lines (297 loc) · 10.9 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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
pr:
branches:
include:
- dev
paths:
exclude:
- docs/*
- README.md
trigger:
branches:
include:
- master
paths:
exclude:
- docs/*
- README.md
- azure-pipelines-ci.yml
- azure-pipelines-ci-cd.yml
stages:
- stage: Build_Stage
displayName: Build Stage
jobs:
- job: WebApp
displayName: Build Web App Job
pool:
name: Hosted Windows 2019 with VS2019
vmImage: 'windows-2019'
demands: java
variables:
BuildConfiguration: release
steps:
- task: DotNetCoreCLI@2
displayName: Restore
inputs:
command: restore
projects: '**/WebApp.csproj'
- powershell: |
Write-Host "Hello World"
$paths = Get-ChildItem -include *.csproj -Recurse
foreach($pathobject in $paths)
{
$path = $pathobject.fullname
$doc = New-Object System.Xml.XmlDocument
$doc.Load($path)
$child = $doc.CreateElement("ProjectGuid")
$child.InnerText = [guid]::NewGuid().ToString().ToUpper()
$node = $doc.SelectSingleNode("//Project/PropertyGroup")
$node.AppendChild($child)
$doc.Save($path)
}
workingDirectory: WebApp
displayName: 'PS : Add Project GUID'
- task: SonarCloudPrepare@1
displayName: Prepare analysis on SonarCloud
inputs:
SonarCloud: SonarCloud
organization: houssemdellai
projectKey: WebAppWithDatabaseDemo
- task: DotNetCoreCLI@2
displayName: Build
inputs:
projects: '**/WebApp.csproj'
arguments: '--configuration $(BuildConfiguration)'
- task: DotNetCoreCLI@2
displayName: Test
inputs:
command: test
projects: '**/*UnitTest*.csproj'
arguments: '--configuration $(BuildConfiguration)'
- task: DotNetCoreCLI@2
displayName: Publish
inputs:
command: publish
publishWebProjects: True
arguments: '--configuration $(BuildConfiguration) --output $(build.artifactstagingdirectory)'
zipAfterPublish: True
- task: SonarCloudAnalyze@1
displayName: Run Code Analysis
- task: SonarCloudPublish@1
displayName: Publish Quality Gate Result
- task: PublishBuildArtifacts@1
displayName: Publish Artifact (WebApp.zip)
inputs:
PathtoPublish: '$(build.artifactstagingdirectory)'
ArtifactName: drop
- job: Database
displayName: Build Database Job
pool:
name: Hosted Windows 2019 with VS2019
vmImage: 'windows-2019'
demands: msbuild
steps:
- task: MSBuild@1
displayName: Build solution WebApp.Database.sqlproj
inputs:
solution: WebApp.Database/WebApp.Database.sqlproj
msbuildArguments: '/p:OutDir=$(Build.ArtifactStagingDirectory)'
- task: PublishBuildArtifacts@1
displayName: Publish Artifact (Dacpac)
inputs:
ArtifactName: dacpac
- job: Selenium
displayName: Build UI Tests Job
pool:
name: Hosted Windows 2019 with VS2019
vmImage: 'windows-2019'
demands: msbuild
steps:
- task: NuGetToolInstaller@0
displayName: Use NuGet 4.3.0
- task: NuGetCommand@2
displayName: NuGet restore
inputs:
restoreSolution: WebAppWithDatabase.sln
- task: MSBuild@1
displayName: Build project SeleniumUiTests.csproj
inputs:
solution: SeleniumUiTests/SeleniumUiTests.csproj
msbuildArguments: '/p:OutDir=$(Build.ArtifactStagingDirectory)'
- task: PublishBuildArtifacts@1
displayName: 'Publish Artifact: UI-Test'
inputs:
ArtifactName: ui-tests
- job: Infrastructure
displayName: Publish Infra files Job
pool:
name: Hosted Ubuntu 1604
vmImage: 'ubuntu-16.04'
steps:
- task: PublishBuildArtifacts@1
displayName: 'Publish Artifact: Terraform'
inputs:
PathtoPublish: Terraform
ArtifactName: terraform
- task: PublishBuildArtifacts@1
displayName: 'Publish Artifact: ARM templates'
inputs:
PathtoPublish: AzureResourceGroupDeployment
ArtifactName: arm
- stage: Dev_Stage
displayName: Dev Stage
dependsOn: Build_Stage
jobs:
- job: Dev
displayName: Deploy to Dev Job
pool:
name: Hosted Windows 2019 with VS2019
vmImage: 'windows-2019'
variables:
Parameters.ConnectedServiceName: 'Microsoft Azure Sponsorship (5a56fb34-f1c5-4669-9412-4592bb81a2cf)' # couldn't be referenced
ResourceGroupName: '$(Prefix)-$(Release.EnvironmentName)-$(UniqueId)-RG'
Database.Admin: 'houssem'
Database.Password: '@Aa123456'
Database.Name: 'EmployeesDB'
WebAppName: '$(Prefix)-$(Release.EnvironmentName)-$(UniqueId)'
WebAppNameUrl: 'https://$(WebAppName).azurewebsites.net/'
SqlServerName: '$(Prefix)-sql-$(Release.EnvironmentName)-$(UniqueId)'
Prefix: 'tunis'
Release.EnvironmentName: 'dev'
UniqueId: '1280' #'$(Build.BuildId)'
steps:
- checkout: none
- task: DownloadBuildArtifacts@0
displayName: Download Build Artifacts
inputs:
artifactName: terraform
downloadPath: $(System.DefaultWorkingDirectory)
- task: Terraform@2
inputs:
TemplatePath: '$(System.DefaultWorkingDirectory)/terraform/'
Arguments: 'init'
InstallTerraform: true
UseAzureSub: true
ConnectedServiceNameSelector: 'ConnectedServiceNameARM'
ConnectedServiceNameARM: 'Microsoft Azure Sponsorship (5a56fb34-f1c5-4669-9412-4592bb81a2cf)'
ManageState: false
- task: Terraform@2
inputs:
TemplatePath: '$(System.DefaultWorkingDirectory)/terraform/'
Arguments: 'plan'
InstallTerraform: true
UseAzureSub: true
ConnectedServiceNameSelector: 'ConnectedServiceNameARM'
ConnectedServiceNameARM: 'Microsoft Azure Sponsorship (5a56fb34-f1c5-4669-9412-4592bb81a2cf)'
ManageState: false
- task: Terraform@2
inputs:
TemplatePath: '$(System.DefaultWorkingDirectory)/terraform/'
Arguments: 'apply'
InstallTerraform: true
UseAzureSub: true
ConnectedServiceNameSelector: 'ConnectedServiceNameARM'
ConnectedServiceNameARM: 'Microsoft Azure Sponsorship (5a56fb34-f1c5-4669-9412-4592bb81a2cf)'
ManageState: false
- task: AzureResourceGroupDeployment@2
displayName: Validate ARM template
enabled: 'false'
inputs:
azureSubscription: 'Microsoft Azure Sponsorship (5a56fb34-f1c5-4669-9412-4592bb81a2cf)'
action: 'Create Or Update Resource Group'
resourceGroupName: '$(ResourceGroupName)'
location: 'West Europe'
templateLocation: 'Linked artifact'
csmFile: '$(System.DefaultWorkingDirectory)/**/arm/WebSiteSQLDatabase.json'
csmParametersFile: '$(System.DefaultWorkingDirectory)/**/arm/WebSiteSQLDatabase.parameters.json'
overrideParameters: '-hostingPlanName "houssemdellai-service-plan" -skuName "F1" -skuCapacity 1 -administratorLogin $(Database.Admin) -administratorLoginPassword $(Database.Password) -databaseName $(Database.Name) -collation "SQL_Latin1_General_CP1_CI_AS" -edition "Basic" -maxSizeBytes "1073741824" -requestedServiceObjectiveName "Basic" -webSiteName $(WebAppName) -sqlserverName $(SqlServerName)'
deploymentMode: Validation
- task: AzureResourceGroupDeployment@2
displayName: Create Or Update Resource Group
enabled: 'false'
inputs:
azureSubscription: 'Microsoft Azure Sponsorship (5a56fb34-f1c5-4669-9412-4592bb81a2cf)'
action: 'Create Or Update Resource Group'
resourceGroupName: '$(ResourceGroupName)'
location: 'West Europe'
templateLocation: 'Linked artifact'
csmFile: '$(System.DefaultWorkingDirectory)/**/arm/WebSiteSQLDatabase.json'
csmParametersFile: '$(System.DefaultWorkingDirectory)/**/arm/WebSiteSQLDatabase.parameters.json'
overrideParameters: '-hostingPlanName "houssemdellai-service-plan" -skuName "F1" -skuCapacity 1 -administratorLogin $(Database.Admin) -administratorLoginPassword $(Database.Password) -databaseName $(Database.Name) -collation "SQL_Latin1_General_CP1_CI_AS" -edition "Basic" -maxSizeBytes "1073741824" -requestedServiceObjectiveName "Basic" -webSiteName $(WebAppName) -sqlserverName $(SqlServerName)'
deploymentMode: Complete
- task: DownloadBuildArtifacts@0
displayName: Download WebApp.zip
inputs:
buildType: 'current'
downloadType: 'single'
artifactName: 'drop'
itemPattern: '**/WebApp.zip'
downloadPath: '$(System.DefaultWorkingDirectory)'
- task: CmdLine@2
inputs:
script: |
ls $(System.DefaultWorkingDirectory)
- task: AzureRmWebAppDeployment@3
displayName: Deploy Web App to Azure App Service
enabled: 'true'
inputs:
azureSubscription: 'Microsoft Azure Sponsorship (5a56fb34-f1c5-4669-9412-4592bb81a2cf)'
appType: 'webApp'
WebAppName: '$(WebAppName)'
TakeAppOfflineFlag: true
JSONFiles: '**/appsettings.json'
packageForLinux: '$(System.DefaultWorkingDirectory)/drop/WebApp.zip' #'$(System.ArtifactsDirectory)/**/drop/WebApp.zip'
- task: DownloadBuildArtifacts@0
displayName: Download DacPac
inputs:
buildType: 'current'
downloadType: 'single'
artifactName: 'dacpac'
itemPattern: '**/*.dacpac'
downloadPath: '$(System.DefaultWorkingDirectory)'
- task: SqlAzureDacpacDeployment@1
displayName: Azure SQL Publish DacPac to SQL Azure
inputs:
azureSubscription: 'Microsoft Azure Sponsorship (5a56fb34-f1c5-4669-9412-4592bb81a2cf)'
ServerName: '$(SqlServerName).database.windows.net,1433'
DatabaseName: '$(Database.Name)'
SqlUsername: '$(Database.Admin)'
SqlPassword: '$(Database.Password)'
DacpacFile: '$(System.DefaultWorkingDirectory)/dacpac/WebApp.Database.dacpac'
- task: DownloadBuildArtifacts@0
displayName: Download Selenium Tests
inputs:
buildType: 'current'
downloadType: 'single'
artifactName: 'ui-tests'
itemPattern: ''
downloadPath: '$(System.DefaultWorkingDirectory)'
- task: VSTest@2
displayName: Selenium UI Tests
inputs:
testSelector: 'testAssemblies'
searchFolder: '$(System.DefaultWorkingDirectory)/ui-tests'
runSettingsFile: '$(System.DefaultWorkingDirectory)/ui-tests/.runsettings'
overrideTestrunParameters: '-webAppUrl $(WebAppNameUrl)'
testAssemblyVer2: '**\*test*.dll
!**\*TestAdapter.dll
!**\obj\**'
runInParallel: false
codeCoverageEnabled: false
- stage: Test_Stage
displayName: Test Stage
jobs:
- job:
displayName: Deploy to Test Job
steps:
- task: CmdLine@2
inputs:
script: 'ls'
- stage: Prod_Stage
displayName: Prod Stage
jobs:
- job:
displayName: Deploy to Prod Job
steps:
- task: CmdLine@2
inputs:
script: 'ls'