-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathazure-pipelines.yml
293 lines (272 loc) · 10.7 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
variables:
- group: azcreds
name: Azure Pipelines
stages:
- stage: Provision
jobs:
- job: TerraformTasks
displayName: Terraform Tasks
pool:
vmImage: 'Ubuntu-18.04'
steps:
# Needed for Terraform VM deployment
- task: DownloadSecureFile@1
displayName: Download azcreds.conf file
name: azcreds
inputs:
secureFile: 'azcreds.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.2.9'
- task: TerraformCLI@0
displayName: Terraform Init
inputs:
command: 'init'
commandOptions: '-backend-config=$(azcreds.secureFilePath)'
backendType: 'azurerm'
backendServiceArm: 'service-connection-azurerm'
backendAzureRmResourceGroupName: 'tfstate'
backendAzureRmStorageAccountName: 'tfstate20932'
backendAzureRmContainerName: 'tfstate'
allowTelemetryCollection: true
workingDirectory: '$(System.DefaultWorkingDirectory)/terraform/environments/test'
- task: TerraformCLI@0
displayName: Terraform Validate
inputs:
command: 'validate'
allowTelemetryCollection: true
- task: AzureCLI@1
displayName: Set Environment Variables for Terraform
inputs:
azureSubscription: service-connection-azurerm
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)
- task: TerraformCLI@0
displayName: 'Terraform Plan'
inputs:
command: 'plan'
environmentServiceName: 'service-connection-azurerm'
allowTelemetryCollection: true
workingDirectory: '$(System.DefaultWorkingDirectory)/terraform/environments/test'
- task: TerraformCLI@0
displayName: Terraform Apply
inputs:
command: 'apply'
environmentServiceName: 'service-connection-azurerm'
workingDirectory: '$(System.DefaultWorkingDirectory)/terraform/environments/test'
allowTelemetryCollection: true
- 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)/automatedtesting/jmeter/fakerestapi'
includeRootFolder: false
archiveType: 'zip'
archiveFile: '$(Build.ArtifactStagingDirectory)/automatedtesting/jmeter/fakerestapi-$(Build.BuildId).zip'
- task: PublishPipelineArtifact@1
displayName: Publish Fakerestapi as Artifact
inputs:
targetPath: '$(Build.ArtifactStagingDirectory)/automatedtesting/jmeter/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: 'service-connection-azurerm'
appType: 'webApp'
WebAppName: 'p3testApp-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:
- job: IntegrationTests
displayName: Integration Tests
pool:
vmImage: ubuntu-18.04
steps:
- task: CmdLine@2
displayName: Install Newman
inputs:
script: 'sudo npm install -g newman'
workingDirectory: $(System.DefaultWorkingDirectory)
- task: CmdLine@2
displayName: Apply Regression Tests
continueOnError: true
inputs:
script: 'newman run ./automatedtesting/postman/regression.json --reporters cli,junit --reporter-junit-export ./automatedtesting/postman/TEST-regression.xml'
workingDirectory: $(System.DefaultWorkingdirectory)
- task: CmdLine@2
displayName: Apply Validation Tests
continueOnError: true
inputs:
script: 'newman run ./automatedtesting/postman/validation.json --reporters cli,junit --reporter-junit-export ./automatedtesting/postman/TEST-validation.xml'
workingDirectory: $(System.DefaultWorkingdirectory)
- task: PublishTestResults@2
displayName: Publish Test Results
inputs:
testResultsFiles: '**/TEST-*.xml'
searchFolder: '$(System.DefaultWorkingDirectory)/automatedtesting/postman/'
publishRunAttachments: true
- job: UITests
displayName: Selenuim UI Tests
steps:
- task: Bash@3
displayName: 'Setup VM environment'
inputs:
targetType: 'inline'
script: |
#! /bin/bash
sudo apt-get upgrade -y
sudo apt-get install python3-pip -y
sudo apt-get install unzip -y
- task: Bash@3
displayName: 'Configure Selenium, Chromium & chromedriver'
inputs:
targetType: 'inline'
script: |
#install chromium & selenium
sudo apt-get install -y chromium-browser
pip3 install selenium
#install chromedriver & export path
if [ ! -f $(Pipeline.Workspace)/chromedriver ]; then
wget https://chromedriver.storage.googleapis.com/100.0.4896.20/chromedriver_linux64.zip
unzip chromedriver_linux64.zip
fi
export PATH=$PATH:$(Pipeline.Workspace)/chromedriver
- task: Bash@3
displayName: 'Run UI test'
inputs:
targetType: 'inline'
script: |
if [ ! -d /var/log/selenium ]; then
sudo mkdir /var/log/selenium
sudo chmod 777 /var/log/selenium
fi
python3 ./automatedtesting/selenium/selenium_ui.py | 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
cat /var/log/selenium/selenium_ui.log
- job: PerformanceTest
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.5.tgz -O jmeter.tgz
tar xzvf jmeter.tgz
mkdir -p log/jmeter
# if [ ! -d /var/log/jmeter ]; then
# sudo mkdir /var/log/jmeter
# sudo chmod 777 /var/log/jmeter
# fi
# if [ ! -d /var/log/jmeter/stress-test-html-report ]; then
# sudo mkdir /var/log/jmeter/stress-test-html-report
# sudo chmod 777 /var/log//stress-test-html-report
# fi
# if [ ! -d /var/log/jmeter/endurance-test-html-report ]; then
# sudo mkdir /var/log/jmeter/endurance-test-html-report
# sudo chmod 777 /var/log/jmeter/endurance-test-html-report
# fi
displayName: Install JMeter
- bash: |
apache-jmeter-5.5/bin/jmeter -n -t automatedtesting/jmeter/stress.jmx \
-l log/jmeter/stress-test-result.csv \
-e -f -o log/jmeter \
-j log/jmeter/jmeter-stress-test.log
displayName: JMeter Stress Test
- bash: |
apache-jmeter-5.5/bin/jmeter -n -t automatedtesting/jmeter/endurance.jmx \
-l log/jmeter/endurance-test-result.csv \
-e -f -o log/jmeter \
-j log/jmeter/jmeter-endurance-test.log
displayName: JMeter Endurance Test
- task: ArchiveFiles@2
displayName: Saving JMeter stress test report to artifact
inputs:
rootFolderOrFile: '$(System.DefaultWorkingDirectory)/log/jmeter'
includeRootFolder: false
archiveType: 'zip'
archiveFile: '$(System.DefaultWorkingDirectory)/log/jmeter-$(Build.BuildId).zip'
verbose: true
- task: ArchiveFiles@2
displayName: Saving JMeter endurance test report to artifact
inputs:
rootFolderOrFile: '$(System.DefaultWorkingDirectory)/log/jmeter'
includeRootFolder: false
archiveType: 'zip'
archiveFile: '$(System.DefaultWorkingDirectory)/log/jmeter-$(Build.BuildId).zip'
verbose: true
- task: PublishPipelineArtifact@1
displayName: Publish JMeter logs
inputs:
targetPath: '$(System.DefaultWorkingDirectory)/log/jmeter'
artifactName: 'drop-jmeter-logs'