Pipeline yaml
Azure DevOps pipelines allow triggering by events within the underlying SCM, for example, "every time a change gets pushed to the master branch. In our case, the SCM is ISPW, and we will trigger the pipeline using Code Pipeline webhooks. Therefore, we do not use trigger.
Agent pool
The agent pool allows specifying requirements for an agent to fulfill in order to be eligible for execution. In our case, we need to run on the only existing local agent, which resides in the Default agent pool.
name: 'Default'
Variables / Constants
Next to the variables defined via the interface, the pipeline will use the variable group mainframe-pipeline-parameters and some additional variables that are used as constants. Refer to the Azure DevOps documentation on how to define and use variables in pipelines.
- group: 'mainframe-pipeline-parameters'
- name: 'gitRepo'
value: 'FTSDEMO_$(ispwApplication)_Unit_Tests'
- name: 'ccSystem'
value: 'AZURE_$(ispwContainerName)'
- name: 'ccDdio'
value: 'SALESSUP.$(ispwApplication).$(ispwLevel).LOAD.SSD'
- name: 'sonarProjectName'
value: 'RNU_$(ispwApplication)_Azure'
- name: 'sonarSources'
value: '.\$(ispwApplication)\MF_Source'
Stages, jobs, tasks
As with Jenkins jobs, there are different elements that help structure the pipeline. Also, they allow defining conditions under which certain tasks get executed, based on results of previous jobs. Refer to the Azure DevOps documentation on details about stages, jobs and tasks.
Stage preparation
The preparation stage clears the workspace to use and downloads the required assets, like sources from ISPW and the Topaz for Total Test projects from GitHub.
displayName: Preparation
jobs:
Job getAssets
displayName: Get Assets from Mainframe and GitHub
steps:
Execute an inline PowerShell script. This script will take the ispwLevel passed by the webhook (DEV1, DEV2, or DEV3), determine the name of the corresponding QA level and create a new variable (echo "##vso[task.setvariable variable=ispwTargetLevel]$ispwTargetLevel"). This latter is necessary, since normal variable definition does not allow this kind of calculation. Therefore, we need to define a new variable during execution.
displayName: Determine ISPW Target Level
name: setTargetLevel
inputs:
targetType: 'inline'
script: |
$ispwTargetLevel = 'QA' + '$(ispwLevel)'.Substring('$(ispwLevel)'.Length - 1, 1)
Write-Host 'Determined Level ' $ispwTargetLevel
echo "##vso[task.setvariable variable=ispwTargetLevel]$ispwTargetLevel"
Execute PowerShell script Clear_Workspace-ps1 to clear the designated workspace on the agent.
displayName: Clear Workspace
inputs:
filePath: '$(agentScriptsPath)\Clear_Workspace.ps1'
arguments: '$(workspaceRoot)'
Execute PowerShell script ISPW_Download_Container-ps1 to download the components in the ISPW container passed by the webhook.
displayName: Download sources for assignment
inputs:
filePath: '$(agentScriptsPath)\ISPW_Download_Container.ps1'
arguments: '$(workspaceRoot) $(hostUri) $(hostPort) $(hostUser) $(hostPassword) $(hostCodePage) $(ispwConfig) $(ispwContainerName) $(ispwContainerType) $(ispwTargetLevel) $(cliPath)'
Execute PowerShell script Git_Clone_TTT_Repo-ps1 to clone the GitHub repository storing the Topaz for Total Test projects.
displayName: Get Unit Tests
inputs:
filePath: '$(agentScriptsPath)\Git_Clone_TTT_Repo.ps1'
arguments: '$(workspaceRoot) $(gitProject)/$(gitRepo)'
Stage tests
This stage executes the downloaded tests and gets the Code Coverage results.
displayName: Tests
jobs:
Job runTests
displayName: Run unit tests and get results
steps:
Execute PowerShell script TTT_Run_Tests-ps1 to execute the tests. The script will execute only tests for those components that have been downloaded for the container.
displayName: Execute Unit Tests
inputs:
filePath: '$(agentScriptsPath)\TTT_Run_Tests.ps1'
arguments: '$(workspaceRoot) $(hostUri) $(hostPort) $(hostUser) $(hostPassword) $(hostCodePage) $(ispwApplication) $(ispwLevel) $(ccRepo) $(ccSystem) $(ccTestId) $(cliPath)'
Execute PowerShell script 'Code_Coverage_Download_Metrics-ps1' to download the Code Coverage results from the mainframe repository to the workspace.
displayName: Get Code Coverage Results
inputs:
filePath: '$(agentScriptsPath)\Code_Coverage_Download_Metrics.ps1'
arguments: '$(workspaceRoot) $(hostUri) $(hostPort) $(hostUser) $(hostPassword) $(hostCodePage) $(ispwApplication) $(ccRepo) $(ccSystem) $(ccTestId) $(ccDdio) $(cliPath)'
Stage qualityGate
This stage will pass the results to SonarQube, query the quality gate status and based on the result, if the quality was passed, trigger the corresponding release pipeline, or regress the assignment, if the quality gate was failed.
displayName: Quality Gate
jobs:
Job sonar
The job will execute the Sonar scanner and query the quality gate.
displayName: run Sonar Scan, Check Quality Gate
steps:
Execute PowerShell script Sonar_Scan-ps1 to pass sources, test results and code coverage data to SonarQube, using the sonar scanner.
displayName: Run Sonar Scanner
inputs:
filePath: '$(agentScriptsPath)\Sonar_Scan.ps1'
arguments: '$(workspaceRoot) $(ispwApplication) $(sonarProjectName) $(sonarSources)'
Job checkQualityGate (conditional)
This job is executed based on the condition, that the job sonar ran successfully.
displayName: Check Quality Gate
dependsOn: sonar
steps:
Execute PowerShell script Sonar_Check_Quality_Gate-ps1 to query the status of the Sonar quality gate.
displayName: Check Sonar Quality Gate
inputs:
filePath: '$(agentScriptsPath)\Sonar_Check_Quality_Gate.ps1'
arguments: '$(sonarServer) $(sonarProjectName) $(sonarAuthorization)'
Job triggerRelease (conditional)
This job is executed based on the condition, that the job checkQualityGate ran successfully, and will trigger the release pipeline.
displayName: Trigger Release Pipeline
dependsOn:
- checkQualityGate
condition: succeeded('checkQualityGate')
steps:
Again, determine the QA level based on the DEV level.
displayName: Determine ISPW Target Level
name: setTargetLevel
inputs:
targetType: 'inline'
script: |
$ispwTargetLevel = 'QA' + '$(ispwLevel)'.Substring('$(ispwLevel)'.Length - 1, 1)
Write-Host 'Determined Level ' $ispwTargetLevel
echo "##vso[task.setvariable variable=ispwTargetLevel]$ispwTargetLevel"
Execute PowerShell script Azure_Trigger_Release.ps1 to trigger an Azure DevOps release pipeline(##create-a-release-pipeline).
displayName: Trigger Release
inputs:
filePath: '$(agentScriptsPath)\Azure_Trigger_Release.ps1'
arguments: '$(azureRestAddress) $(azureOrganization) $(System.TeamProject) "$(azureRestAuthorization)" $(ispwApplication) $(ispwContainerName) $(ispwContainerType) $(ispwTargetLevel) $(releaseDefinitionId)'
Job regressAssigment (conditional)
This job is executed based on the condition, that the job checkQualityGate failed, and will regress the Code Pipeline assignment.
dependsOn:
- checkQualityGate
condition: failed('checkQualityGate')
steps:
Again, determine the QA level based on the DEV level.
displayName: Determine ISPW Target Level
name: setTargetLevel
inputs:
targetType: 'inline'
script: |
$ispwTargetLevel = 'QA' + '$(ispwLevel)'.Substring('$(ispwLevel)'.Length - 1, 1)
Write-Host 'Determined Level ' $ispwTargetLevel
echo "##vso[task.setvariable variable=ispwTargetLevel]$ispwTargetLevel"
Execute PowerShell script ISPW_Operations-ps1to regress the Code Pipeline assignment
displayName: Regress Assignment
inputs:
filePath: '$(agentScriptsPath)\ISPW_Operations.ps1'
arguments: 'ContainerOperation $(cesUri) $(ispwConfig) assignments regress $(ispwContainerName) $(ispwTargetLevel) $(cesToken) FTSDEMO $(ispwApplication) $(ispwServer)'