-
Notifications
You must be signed in to change notification settings - Fork 3
/
azure-pipelines.yml
322 lines (300 loc) · 11.3 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
variables:
- group: azurecreds
trigger:
- master
stages:
- stage: Provision
jobs:
- job: TerraformTasks
displayName: Terraform Tasks
pool:
vmImage: 'ubuntu-18.04'
steps:
#Download azurecreds.conf File
- task: DownloadSecureFile@1
displayName: Download azurecreds.conf file
name: azurecreds
inputs:
secureFile: 'azurecreds.conf'
# Install SSH Key for VM
- task: InstallSSHKey@0
displayName: Install SSH key
inputs:
knownHostsEntry: 'known_hosts'
sshPublicKey: $(public_key)
sshKeySecureFile: 'id_rsa'
#Terraform Install
- task: TerraformInstaller@0
displayName: Terraform Install
inputs:
terraformVersion: '1.0.1'
#Terraform Init
- task: TerraformTaskV2@2
displayName: Terraform Init
inputs:
provider: 'azurerm'
command: 'init'
commandOptions: '-backend-config=$(azurecreds.secureFilePath)'
backendServiceArm: 'azurerm-sc'
backendAzureRmResourceGroupName: 'tstate'
backendAzureRmStorageAccountName: 'tstate19206'
backendAzureRmContainerName: 'tstate'
backendAzureRmKey: 'test.terraform.tfstate'
workingDirectory: '$(System.DefaultWorkingDirectory)/terraform/environments/test'
- task: AzureCLI@1
displayName: Set Environment Variables for Terraform
inputs:
azureSubscription: azurerm-sc
scriptLocation: inlineScript
workingDirectory: '$(System.DefaultWorkingDirectory)/terraform/environments/test'
addSpnToEnvironment: true
inlineScript: |
export ARM_CLIENT_ID=$(client_id)
export ARM_CLIENT_SECRET=$(client_secret)
export ARM_SUBSCRIPTION_ID=$(subscription_id)
export ARM_TENANT_ID=$(tenant_id)
#Terraform Apply
- task: TerraformTaskV2@2
displayName: Terraform Apply
inputs:
provider: 'azurerm'
command: 'apply'
commandOptions: '-auto-approve'
workingDirectory: '$(System.DefaultWorkingDirectory)/terraform/environments/test'
environmentServiceNameAzureRM: 'azurerm-sc'
- stage: Build
jobs:
- job: build_artifacts
displayName: Build Artifacts
pool:
vmImage: 'ubuntu-18.04'
steps:
- task: ArchiveFiles@2
displayName: Archive FakeRestAPI
inputs:
rootFolderOrFile: '$(System.DefaultWorkingDirectory)/fakerestapi'
includeRootFolder: false
archiveType: 'zip'
archiveFile: '$(Build.ArtifactStagingDirectory)/fakerestapi-$(Build.BuildId).zip'
- task: PublishPipelineArtifact@1
displayName: Publish FakeRestAPI artifact
inputs:
targetPath: '$(Build.ArtifactStagingDirectory)/fakerestapi-$(Build.BuildId).zip'
artifactName: 'drop-fakerestapi'
- task: ArchiveFiles@2
displayName: Archive Selenium
inputs:
rootFolderOrFile: '$(System.DefaultWorkingDirectory)/automatedtesting/selenium'
includeRootFolder: false
archiveType: 'zip'
archiveFile: '$(Build.ArtifactStagingDirectory)/selenium-$(Build.BuildId).zip'
- task: PublishPipelineArtifact@1
displayName: Publish Selenium artifact
inputs:
targetPath: '$(Build.ArtifactStagingDirectory)/selenium-$(Build.BuildId).zip'
artifactName: 'drop-selenium'
- stage: Deploy
jobs:
- deployment: deploy_fakerestapi
displayName: Deploy FakeRestAPI
pool:
vmImage: 'ubuntu-18.04'
environment: 'TEST'
strategy:
runOnce:
deploy:
steps:
- task: AzureRmWebAppDeployment@4
inputs:
ConnectionType: 'AzureRM'
azureSubscription: 'azurerm-sc'
appType: 'webApp'
WebAppName: 'udacitytest-AppService'
packageForLinux: '$(Pipeline.Workspace)/drop-fakerestapi/fakerestapi-$(Build.BuildId).zip'
DeploymentType: zipDeploy
- deployment: VMDeploy
displayName: Deploy Virtual Machine
environment:
name: 'TEST'
resourceType: VirtualMachine
strategy:
runOnce:
deploy:
steps:
- bash: |
sudo apt-get update -y
sudo apt-get install python3-pip -y
sudo apt-get install unzip -y
sudo apt-get install -y chromium-browser
sudo apt-get install -y chromium-chromedriver
python3 -m pip install --upgrade pip
pip3 install selenium
# Install Log Analytics agent on Linux computers (only need to run once, comment when installed)
# wget https://raw.githubusercontent.com/Microsoft/OMS-Agent-for-Linux/master/installer/scripts/onboard_agent.sh && sh onboard_agent.sh -w ${AZURE_LOG_ANALYTICS_ID} -s ${AZURE_LOG_ANALYTICS_PRIMARY_KEY} -d opinsights.azure.com
env:
AZURE_LOG_ANALYTICS_ID: $(la_workspace_id)
AZURE_LOG_ANALYTICS_PRIMARY_KEY: $(la_primary_key)
displayName: Configure VM
- stage: Test
jobs:
- deployment: test_vm
displayName: Test on Virtual Machine
environment:
name: 'TEST'
resourceType: VirtualMachine
strategy:
runOnce:
deploy:
steps:
- bash: |
cd $(Pipeline.Workspace)/drop-selenium
unzip -o selenium-$(Build.BuildId).zip
sudo mkdir -p /var/log/selenium
sudo chmod 777 /var/log/selenium
python3 -u selenium-test.py 2>&1 | sudo tee -a /var/log/selenium/selenium-test.log
cd $(System.DefaultWorkingDirectory)
mkdir -p log/selenium
sudo cp /var/log/selenium/selenium-test.log log/selenium/selenium-test.log
displayName: Run Selenium tests
- task: PublishPipelineArtifact@1
displayName: Publish Selenium logs
inputs:
targetPath: '$(System.DefaultWorkingDirectory)/log/selenium/selenium-test.log'
artifactName: 'drop-selenium-logs'
- job: test_jmeter
displayName: Test JMeter
pool:
vmImage: 'ubuntu-18.04'
steps:
- bash: |
sudo apt-get install openjdk-11-jre-headless -y
java -version
wget https://archive.apache.org/dist/jmeter/binaries/apache-jmeter-5.4.tgz -O jmeter.tgz
tar xzvf jmeter.tgz
mkdir -p log/jmeter
displayName: Install JMeter
- bash: |
apache-jmeter-5.4/bin/jmeter -n -t automatedtesting/jmeter/stress-test.jmx \
-l log/jmeter/stress-test-result.csv \
-e -f -o log/jmeter/stress-test-html-report \
-j log/jmeter/jmeter-stress-test.log
displayName: JMeter Stress Test
- bash: |
apache-jmeter-5.4/bin/jmeter -n -t automatedtesting/jmeter/endurance-test.jmx \
-l log/jmeter/endurance-test-result.csv \
-e -f -o log/jmeter/endurance-test-html-report \
-j log/jmeter/jmeter-endurance-test.log
displayName: JMeter Endurance Test
- task: ArchiveFiles@2
displayName: Save JMeter Stress Test Report to Artifact
inputs:
rootFolderOrFile: '$(System.DefaultWorkingDirectory)/log/jmeter/stress-test-html-report'
includeRootFolder: false
archiveType: 'zip'
archiveFile: '$(System.DefaultWorkingDirectory)/log/jmeter/stress-test-html-report-$(Build.BuildId).zip'
verbose: true
- task: ArchiveFiles@2
displayName: Save JMeter Endurance Test Report to Artifact
inputs:
rootFolderOrFile: '$(System.DefaultWorkingDirectory)/log/jmeter/endurance-test-html-report'
includeRootFolder: false
archiveType: 'zip'
archiveFile: '$(System.DefaultWorkingDirectory)/log/jmeter/endurance-test-html-report-$(Build.BuildId).zip'
verbose: true
- task: PublishPipelineArtifact@1
displayName: Publish JMeter logs
inputs:
targetPath: '$(System.DefaultWorkingDirectory)/log/jmeter'
artifactName: 'drop-jmeter-logs'
- job: TestNewman
displayName: Test Postman with Newman CLI
pool:
vmImage: 'ubuntu-18.04'
steps:
- task: NodeTool@0
displayName: Install Node v12.X
inputs:
versionSpec: '12.x'
- bash: |
npm install -g newman
mkdir -p log/newman
displayName: Install Newman CLI
- bash: |
newman run automatedtesting/postman/regressionTestUdacity.postman_collection.json \
-e automatedtesting/postman/testingenvironment.postman_environment.json \
--reporters cli,junit \
--reporter-junit-export log/newman/regressionTestUdacity.xml \
--suppress-exit-code
displayName: Run Regression Test
- bash: |
newman run automatedtesting/postman/validationTestUdacity.postman_collection.json \
-e automatedtesting/postman/testingenvironment.postman_environment.json \
--reporters cli,junit \
--reporter-junit-export log/newman/validationTestUdacity.xml \
--suppress-exit-code
displayName: Run Validation Test
- task: PublishPipelineArtifact@1
displayName: Publish Newman logs
inputs:
targetPath: '$(System.DefaultWorkingDirectory)/log/newman'
artifactName: 'drop-newman-logs'
- task: PublishTestResults@2
displayName: 'Publish Postman Test Results'
inputs:
testRunner: 'JUnit'
searchFolder: '$(System.DefaultWorkingDirectory)/log/newman'
testResultsFiles: '*.xml'
mergeTestResults: true
testRunTitle: 'Postman Test Results'
#- stage: Destroy
# jobs:
# - job: destroy_azure_infrastructure
# displayName: Destroy Azure Infrastructure
# pool:
# vmImage: 'ubuntu-18.04'
# steps:
#
# #Download azurecreds.conf File
# - task: DownloadSecureFile@1
# displayName: Download azurecreds.conf file
# name: azurecreds
# inputs:
# secureFile: 'azurecreds.conf'
#
# # Install SSH Key for VM
# - task: InstallSSHKey@0
# displayName: Install SSH key
# inputs:
# knownHostsEntry: 'known_hosts'
# sshPublicKey: $(public_key)
# sshKeySecureFile: 'id_rsa'
#
# #Terraform Install
# - task: TerraformInstaller@0
# displayName: Terraform Install
# inputs:
# terraformVersion: '1.0.1'
#
# #Terraform Init
# - task: TerraformTaskV2@2
# displayName: Terraform Init
# inputs:
# provider: 'azurerm'
# command: 'init'
# commandOptions: '-backend-config=$(azurecreds.secureFilePath)'
# backendServiceArm: 'azurerm-sc'
# backendAzureRmResourceGroupName: 'tstate'
# backendAzureRmStorageAccountName: 'tstate19206'
# backendAzureRmContainerName: 'tstate'
# backendAzureRmKey: 'test.terraform.tfstate'
# workingDirectory: '$(System.DefaultWorkingDirectory)/terraform/environments/test'
#
# - task: TerraformTaskV2@2
# displayName: Terraform Destroy
# inputs:
# provider: 'azurerm'
# command: 'destroy'
# commandOptions: |
# -auto-approve
# workingDirectory: '$(System.DefaultWorkingDirectory)/terraform/environments/test'
# environmentServiceNameAzureRM: 'azurerm-sc'