forked from udacity/cd1807-Project-Ensuring-Quality-Releases
-
Notifications
You must be signed in to change notification settings - Fork 0
/
azure-pipelines.yaml
252 lines (233 loc) · 10.8 KB
/
azure-pipelines.yaml
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
name: Azure Pipelines
# Start with a minimal pipeline that you can customize to build and deploy your code.
# Add steps that build, run tests, deploy, and more:
# https://aka.ms/yaml
trigger:
- main
# ToDo: Replace the agent pool name, if you are using Udacity Cloud lab.
# Otherwise, comment out the line below.
pool: myAgentPool
variables:
python.version: '3.7.6'
# ToDo: Replace the service connection name as used in the DevOps project settings
azureServiceConnectionId: 'myServiceConnection'
# Project root folder. Point to the folder containing manage.py file.
projectRoot: $(System.DefaultWorkingDirectory)
# Environment name
environmentName: 'test'
stages:
#--------------------------------------------#
# BUILD STAGE
#--------------------------------------------#
- stage: Build
jobs:
- job: BuildInfrastructure
steps:
#--------------------------------------------#
# Use Terraform to create the Infrastructure
# Install Terraform on the pipeline agent
- task: ms-devlabs.custom-terraform-tasks.custom-terraform-installer-task.TerraformInstaller@0
displayName: 'Terrafom installation'
inputs:
terraformVersion: '1.2.9'
# Run Terraform Init on the pipeline agent
# ToDo: Replace the resource group name, storage account name, and container name below
- task: ms-devlabs.custom-terraform-tasks.custom-terraform-release-task.TerraformTaskV3@3
displayName: 'Terrafom init'
inputs:
provider: 'azurerm'
command: 'init'
workingDirectory: '$(System.DefaultWorkingDirectory)/terraform/environments/test'
backendServiceArm: '$(azureServiceConnectionId)'
backendAzureRmResourceGroupName: ''
backendAzureRmStorageAccountName: ''
backendAzureRmContainerName: ''
backendAzureRmKey: 'test.terraform.tfstate'
- task: ms-devlabs.custom-terraform-tasks.custom-terraform-release-task.TerraformTaskV3@3
displayName: Terraform validate
inputs:
provider: 'azurerm'
command: 'validate'
# OPTIONAL - This step is needed only if your Terraform VM uses an SSH key pair for login and you want your pipeline agent to connect to it.
# Generate an SSH key pair in your local/AZ Cloud shell. Use the public key in the Terraform VM module.
# Install public key and private key file to the pipeline agent, using the task below.
# ToDo: Change the inputs value below
# - task: InstallSSHKey@0
# inputs:
# knownHostsEntry: 'KNOWN_HOSTS_STRING' # variable value
# sshPublicKey: 'PUBLIC_KEY' # variable value
# sshKeySecureFile: 'id_rsa' # Use secure file feature in the pipeline library UI to save the "id_rsa" file, as mentioned here: https://learn.microsoft.com/en-us/azure/devops/pipelines/library/secure-files?view=azure-devops#add-a-secure-file
# - task: DownloadSecureFile@1
# name: udacity_public_key
# displayName:
# inputs:
# secureFile:
# Run Terraform Apply
- task: ms-devlabs.custom-terraform-tasks.custom-terraform-release-task.TerraformTaskV3@3
displayName: Terraform apply
inputs:
provider: 'azurerm'
command: 'apply'
workingDirectory: '$(System.DefaultWorkingDirectory)/terraform/environments/test'
environmentServiceNameAzureRM: '$(azureServiceConnectionId)'
# ToDo: Change the workingDirectory path, as applicable to you
# Destroy the resources in Azure by running a separate pipeline.
# - task: TerraformTaskV3@3
# displayName: Terraform destroy
# inputs:
# provider: 'azurerm'
# command: 'destroy'
# workingDirectory: '$(System.DefaultWorkingDirectory)/terraform/environments/test'
# environmentServiceNameAzureRM: '$(azureServiceConnectionId)'
#--------------------------------------------#
# Postman - Install Newman
# ToDo: Update the command and verify the working directory
- task: CmdLine@2
displayName: Install Newman
inputs:
script: 'sudo npm install -g newman'
workingDirectory: $(System.DefaultWorkingDirectory)
# Postman Data Validation Test Suite
# ToDo: Verify the working directory
- task: CmdLine@2
displayName: Run Data Validation Tests
continueOnError: true
inputs:
script: 'newman run TestSuite.Data-Validation.json -e Test.environment.json --reporters cli,junit --reporter-junit-export TEST-DataValidation.xml'
workingDirectory: '$(System.DefaultWorkingDirectory)/automatedtesting/postman'
# Postman Regression Test Suite
# ToDo: Verify the working directory
- task: CmdLine@2
displayName: Run Regression Tests
continueOnError: true
inputs:
script: 'newman run TestSuite.Regression.json -e Test.environment.json --reporters cli,junit --reporter-junit-export TEST-Regression.xml'
workingDirectory: '$(System.DefaultWorkingDirectory)/automatedtesting/postman'
# Postman - Publish Results
# ToDo: Complete the task as explained here: https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/test/publish-test-results?view=azure-devops&tabs=trx%2Cyaml#yaml-snippet
- task: PublishTestResults@2
inputs:
testResultsFormat: 'JUnit'
testResultsFiles: '**/TEST-*.xml'
searchFolder: # ToDo
mergeTestResults: true
testRunTitle: # ToDo
#--------------------------------------------#
# Selenium (UI) Test Suite - Archive the package
# "ArchiveFiles@2" picks up the web package and archives it.
- task: ArchiveFiles@2
displayName: 'Archive UI Tests'
inputs:
rootFolderOrFile: '$(System.DefaultWorkingDirectory)/automatedtesting/selenium'
includeRootFolder: false
archiveType: 'zip'
archiveFile: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId)-uitests.zip'
# Selenium Test Suite - Publish the package
- publish: $(Build.ArtifactStagingDirectory)/$(Build.BuildId)-uitests.zip # Same as the archiveFile artifact above.
displayName: 'Upload Package'
artifact: drop-uitests
#--------------------------------------------#
# FakeRestAPI - Archive
# ToDo: Complete the ArchiveFiles@2 task and publish step
- task: ArchiveFiles@2
displayName: 'Archive FakeRestAPI'
inputs:
rootFolderOrFile:
includeRootFolder: false
archiveType: 'zip'
archiveFile: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId)-fakerestapi.zip'
- publish: $(Build.ArtifactStagingDirectory)/$(Build.BuildId)-fakerestapi.zip
displayName: 'Upload Package'
artifact: drop-fakerestapi
#--------------------------------------------#
# JMeter (Performance) Test Suite - Archive
# ToDo: Complete the ArchiveFiles@2 task and publish step
- task: ArchiveFiles@2
displayName: 'Archive PerformanceTestSuite'
inputs:
rootFolderOrFile:
includeRootFolder: false
archiveType: 'zip'
archiveFile: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId)-perftests.zip'
# JMeter Test Suite - Publish
- publish: $(Build.ArtifactStagingDirectory)/$(Build.BuildId)-perftests.zip
displayName: 'Upload Package'
artifact: drop-perftests
#--------------------------------------------#
# DEPLOYMENT STAGE
#--------------------------------------------#
- stage: Deploy
jobs:
#--------------------------------------------#
# Deploy FakeRestAPI Web App
# ToDo: Provide <environment name> you created in your DevOps project
- deployment: FakeRestAPI
pool:
vmImage: 'Ubuntu-18.04'
environment: <environment name> # ToDo
strategy:
runOnce:
deploy:
steps:
- task: AzureWebApp@1
displayName: 'Deploy Azure Web App'
inputs:
azureSubscription: '' # ToDo
appName: '' # ToDo
appType: webApp
package: $(Pipeline.Workspace)/<artifact>/<archiveFile> # ToDo: Use the published zip artifact.
#--------------------------------------------#
# Run JMeter test suite against the App Service
- task: CmdLine@2
inputs:
script: |
wget "https://apache.mirrors.lucidnetworks.net//jmeter/binaries/apache-jmeter-5.2.1.tgz"
tar -xf apache-jmeter-5.2.1.tgz
unzip -o $(Build.BuildId)-perftests.zip
./apache-jmeter-5.2.1/bin/jmeter -n -t PerformanceTestSuite.jmx -j jmeter.log -f
cat jmeter.log # ToDo: Write your commands
workingDirectory: $(Pipeline.Workspace)/<artifact> # ToDo: Use the artifact name from the task above
#--------------------------------------------#
# Selenium | Functional UI Tests
# ToDo:
- deployment: VMDeploy
displayName: Selenium Tests
environment:
name: # ToDo: Change/provide a name
resourceType: VirtualMachine
tags: selenium
strategy:
runOnce:
deploy:
steps:
- download: current
artifact: drop-ui-tests # ToDo: Change/provide a name
- task: Bash@3
inputs:
targetType: 'inline'
script: |
#! /bin/bash
sudo apt-get upgrade -y
sudo apt-get install python3-pip -y
sudo apt-get install unzip -y
sudo apt-get install -y chromium-browser
pip3 install selenium
cd ~/
DIR=/home/testuser/app
if [ ! -d "$DIR" ]; then
mkdir app
fi
mv /home/testuser/azagent/_work/1/drop-uitests/$(Build.BuildId)-uitests.zip app
cd app
unzip -o $(Build.BuildId)-uitests.zip
FILE=/home/testuser/app/chromedriver_linux64.zip
if [ ! -f "$FILE" ]; then
LATEST=$(wget -q -O - http://chromedriver.storage.googleapis.com/LATEST_RELEASE)
wget http://chromedriver.storage.googleapis.com/$LATEST/chromedriver_linux64.zip
unzip -o chromedriver_linux64.zip
sudo ln -s $PWD/chromedriver /usr/local/bin/chromedriver
fi
export PATH=$PATH:/home/testuser/app
echo "Starting Selenium Tests"
python3 add_remove_from_cart.py >> selenium.log
echo "Completed Selenium Tests. Check selenium.log for results."