项目作者: subaquatic-pierre

项目描述 :
CI / CD Test Automation Pipeline - Azure DevOps
高级语言: JavaScript
项目地址: git://github.com/subaquatic-pierre/azure-test-automation.git
创建时间: 2020-09-27T18:10:33Z
项目社区:https://github.com/subaquatic-pierre/azure-test-automation

开源协议:

下载


CI / CD Test Automation Pipeline - Azure DevOps

Dependencies

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.

Azure Resources

  1. Azure Free account
  2. Azure Storage account (resource)
  3. Azure Log Workspace (resource)
  4. Terraform Service principle (resource)
  5. Azure DevOps Organization
  6. Azure CLI (resource)

Locally Installed Dependencies

Scripts can be found in the Resource section

  1. Jmeter
  2. Postman
  3. Newman
  4. Terraform resource

Steps

  1. Clone this repo
  1. git clone https://github.com/subaquatic-pierre/ci-cd-test-automation.git
  1. Create AzurePipeLine Project (resource)

  2. Link Project to GitHub repo (resource)

  3. Update ‘terraform.tfvars.example’ to include your credentials, update file name to remove ‘.example’ extension.

  1. # Azure subscription vars
  2. subscription_id = "YOUR_CREDENTIALS"
  3. client_id = "YOUR_CREDENTIALS"
  4. client_secret = "YOUR_CREDENTIALS"
  5. tenant_id = "YOUR_CREDENTIALS"
  6. # Resource Group/Location
  7. location = "YOUR_CREDENTIALS"
  8. resource_group = "YOUR_CREDENTIALS"
  9. application_type = "YOUR_CREDENTIALS"
  10. # Network
  11. virtual_network_name = "YOUR_CREDENTIALS"
  12. address_space = ["10.5.0.0/16"]
  13. address_prefix_test = "10.5.1.0/24"
  1. From the command line, change into terraform directory
  1. cd terraform
  1. Run Terraform init and apply commands. Enter ‘yes’ once prompted to run plan
  1. terraform init
  2. terraform apply
  1. Add Virtual machine to CITESTING Environment (resource)

  2. Create SSH key-pair to be used with GitHub and Azure Pipelines (resource)

  3. Create Service Connection in DevOps project

  4. Update ‘azure-pipelines.yaml’ to include your SSH key (resource)

  1. - task: InstallSSHKey@0
  2. inputs:
  3. knownHostsEntry: "GITHUB_HOSTS"
  4. sshPublicKey: "YOUR_PUBLIC_KEY"
  5. sshKeySecureFile: "YOUR_SECURE_FILE"
  1. Update ‘azureSubscription’ and ‘appName’ in Deploy stage in ‘azure-pipelines.yaml’

Get Service connection ID to be used in azureSubscription variable below

  1. https://dev.azure.com/{organization}/{project}/_apis/serviceendpoint/endpoints?api-version=5.0-preview.2
  1. azureSubscription: "8946b145-1fad-4823-a128-5f486158f331"
  2. appName: "testautomation-appservice"
  1. Create Log Analytics Workspace (resource)

  2. Link Virtual Machine to Log Work Space (resource)

  3. Create custom log file (resource)

The log path name should be the following:

  1. /var/log/selenium/*.log
  1. Connect App Service to Write logs to Azure Log Workspace

  2. Create Alert Group for the App Service

  3. 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

  4. Write Selenium tests in ‘selenium/selenium_test.py’

  5. Uncomment line 32 in ‘azure-pipelines’ to run Postman tests in Build environment

  6. Make one last git commit and push for pipeline to trigger the final build

  1. git add .
  2. git commit -m 'Final build'
  3. git push

Resources

Jmeter installation script

Change into the directory which you wish to install Jmeter package

  1. cd /usr/lib

Run the below installation script. It will download Jmeter and add a symlink to your PATH

  1. #! /bin/bash
  2. echo "Downloading Jmeter ..."
  3. wget https://downloads.apache.org//jmeter/binaries/apache-jmeter-5.3.tgz
  4. echo "Unpacking jmeter tgz ..."
  5. tar -xzvf apache-jmeter-5.3.tgz
  6. echo "Create symlink to jmeter bin file"
  7. sudo ln -s ./apache-jmeter-5.3/bin/jmeter /usr/bin/jmeter
  8. echo "Removing jmeter tgz ..."
  9. sudo rm -rf apache-jmeter-5.3.tgz

Selenium and ChromeDriver installation

Install selenium and add chrome-driver to PATH
e

  1. sudo apt-get upgrade -y
  2. sudo apt-get install python3-pip -y
  3. sudo apt-get install unzip -y
  4. sudo apt-get install -y chromium-browser
  5. pip3 install selenium
  6. export PATH=$PATH:/usr/bin/chromebrowser

Install Postman and Newman

  1. sudo apt-get upgrade -y
  2. sudo snap install postman
  3. sudo npm install -g newman reporter

Official Guides

- Create Azure DevOps Project

https://docs.microsoft.com/en-us/azure/devops/organizations/projects/create-project?view=azure-devops&tabs=preview-page

https://docs.microsoft.com/en-us/azure/devops/pipelines/repos/github?view=azure-devops&tabs=yaml

- Create Azure Storage account for Terraform

https://docs.microsoft.com/en-us/azure/developer/terraform/store-state-in-azure-storage

- Create Terraform Service Principal

https://www.terraform.io/docs/providers/azurerm/guides/service_principal_client_secret.html

- Create Azure Log Workspace

https://docs.microsoft.com/en-us/azure/azure-monitor/learn/quick-create-workspace

- Install Azure CLI

https://docs.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latest

- Create custom log file

https://docs.microsoft.com/en-us/azure/azure-monitor/platform/data-sources-custom-logs

- Connect VM to Log Anazlytics workspace

https://docs.microsoft.com/en-us/azure/azure-monitor/learn/quick-collect-azurevm

- Create CI/CD Testing Environment

https://docs.microsoft.com/en-us/azure/devops/pipelines/ecosystems/deploy-linux-vm?view=azure-devops&tabs=java

- Create SSH key pair

https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/utility/install-ssh-key?view=azure-devops