Azure DevOps YAML pipelines now support the stringList parameter type, which allows you to present multiple selectable options as checkboxes in the pipeline UI.
This blog explains a pipeline that uses a stringList parameter with three values: dev, qa, and prod. After adding the region parameter as a stringList, the pipeline looks similar to the image below.
Find the sample YAML pipeline script below. It creates multiple pipeline stages based on the values provided in the region parameter.
parameters:
- name: regions
type: stringList
displayName: Regions
values:
- Dev
- QA
- Prd
stages:
- stage: Build_AND_Test
displayName: "build and test"
jobs:
- job: BuildAndTestJob
steps:
- task: PowerShell@2
inputs:
targetType: 'inline'
script: |
Write-Host "This is build and unit test stage"
- ${{ each stage in parameters.regions }}:
- stage: ${{ stage }}
displayName: Deploy to ${{ stage }}
jobs:
- job: DeployJob_${{ stage }}
displayName: Deploy job for ${{ stage }}
steps:
- task: PowerShell@2
displayName: Print stage name
inputs:
targetType: 'inline'
script: |
Write-Host "Running deployment for environment: ${{ stage }}"
After running the pipeline with all three-parameter values dev, qa, and prod selected, the pipeline run will appear as shown below.
No comments:
Post a Comment