CI / CD Test Automation Pipeline - Azure DevOps
Before starting this walk-through, you will need to have the following resources installed. Please follow the resource guides to install all dependencies if you do not already have them.
Scripts can be found in the Resource section
git clone https://github.com/subaquatic-pierre/ci-cd-test-automation.git
Create AzurePipeLine Project (resource)
Link Project to GitHub repo (resource)
Update ‘terraform.tfvars.example’ to include your credentials, update file name to remove ‘.example’ extension.
# Azure subscription vars
subscription_id = "YOUR_CREDENTIALS"
client_id = "YOUR_CREDENTIALS"
client_secret = "YOUR_CREDENTIALS"
tenant_id = "YOUR_CREDENTIALS"
# Resource Group/Location
location = "YOUR_CREDENTIALS"
resource_group = "YOUR_CREDENTIALS"
application_type = "YOUR_CREDENTIALS"
# Network
virtual_network_name = "YOUR_CREDENTIALS"
address_space = ["10.5.0.0/16"]
address_prefix_test = "10.5.1.0/24"
cd terraform
terraform init
terraform apply
Add Virtual machine to CITESTING Environment (resource)
Create SSH key-pair to be used with GitHub and Azure Pipelines (resource)
Create Service Connection in DevOps project
Update ‘azure-pipelines.yaml’ to include your SSH key (resource)
- task: InstallSSHKey@0
inputs:
knownHostsEntry: "GITHUB_HOSTS"
sshPublicKey: "YOUR_PUBLIC_KEY"
sshKeySecureFile: "YOUR_SECURE_FILE"
Get Service connection ID to be used in azureSubscription variable below
https://dev.azure.com/{organization}/{project}/_apis/serviceendpoint/endpoints?api-version=5.0-preview.2
azureSubscription: "8946b145-1fad-4823-a128-5f486158f331"
appName: "testautomation-appservice"
Create Log Analytics Workspace (resource)
Link Virtual Machine to Log Work Space (resource)
Create custom log file (resource)
The log path name should be the following:
/var/log/selenium/*.log
Connect App Service to Write logs to Azure Log Workspace
Create Alert Group for the App Service
Change directory into ‘jmeter’. Open Jmeter application and open the stress_test_suite.jmx’ or ‘endurance_test_suite.jmx’ to edit the suite. Save the suites with their respective names. Edit URL to point to your WebAppService
Write Selenium tests in ‘selenium/selenium_test.py’
Uncomment line 32 in ‘azure-pipelines’ to run Postman tests in Build environment
Make one last git commit and push for pipeline to trigger the final build
git add .
git commit -m 'Final build'
git push
Change into the directory which you wish to install Jmeter package
cd /usr/lib
Run the below installation script. It will download Jmeter and add a symlink to your PATH
#! /bin/bash
echo "Downloading Jmeter ..."
wget https://downloads.apache.org//jmeter/binaries/apache-jmeter-5.3.tgz
echo "Unpacking jmeter tgz ..."
tar -xzvf apache-jmeter-5.3.tgz
echo "Create symlink to jmeter bin file"
sudo ln -s ./apache-jmeter-5.3/bin/jmeter /usr/bin/jmeter
echo "Removing jmeter tgz ..."
sudo rm -rf apache-jmeter-5.3.tgz
Install selenium and add chrome-driver to PATH
e
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
export PATH=$PATH:/usr/bin/chromebrowser
sudo apt-get upgrade -y
sudo snap install postman
sudo npm install -g newman reporter
https://docs.microsoft.com/en-us/azure/devops/pipelines/repos/github?view=azure-devops&tabs=yaml
https://docs.microsoft.com/en-us/azure/developer/terraform/store-state-in-azure-storage
https://www.terraform.io/docs/providers/azurerm/guides/service_principal_client_secret.html
https://docs.microsoft.com/en-us/azure/azure-monitor/learn/quick-create-workspace
https://docs.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latest
https://docs.microsoft.com/en-us/azure/azure-monitor/platform/data-sources-custom-logs
https://docs.microsoft.com/en-us/azure/azure-monitor/learn/quick-collect-azurevm