I have an azurePipeline that have some parameters defined in a template file called
alerts-parameters.yml
parameters:
alerts:
- alertName: 'ex1'
- alertName: 'ex2'
- alertName: 'ex3'
In the pipeline I am defining the parameters as template under variables and iterating on those parameters and execute simple pipeline but it’s not able to identify the alerts to iterate on it.
azurePipeline.yml
variables:
- template: alerts-parameters.yml
jobs:
- job: ValidateAlert
displayName: 'ValidateAlert'
pool:
vmImage: 'ubuntu-latest'
steps:
- ${{ each alert in parameters.alerts }}:
- task: AzureCLI@2
displayName: 'Validate Alert: ${{ alert.alertName }}'
inputs:
azureSubscription: $(ResourceGroup)
scriptType: 'bash'
scriptLocation: 'inlineScript'
inlineScript: |
echo "Validating alert: ${{ alert.alertName }}"
Azure pipeline error
/azurePipeline.yml (Line: 10, Col: 7): Key not found 'alerts'
N.B: It works if the parameters are defined in the same AzurePiplien file but I am trying to add those parameters in another template file as they are huge (this is simplified example)
Working Example:
parameters:
- name: alerts
type: object
default:
- alertName: 'ex1'
alertParam: '1'
- alertName: 'ex2'
alertParam: '2'
- alertName: 'ex3'
alertParam: '3'
jobs:
- job: ValidateAlert
displayName: 'ValidateAlert'
pool:
vmImage: 'ubuntu-latest'
steps:
- ${{ each alert in parameters.alerts }}:
- task: AzureCLI@2
displayName: 'Validate Alert: ${{ alert.alertName }}'
inputs:
azureSubscription: $(ResourceGroup)
scriptType: 'bash'
scriptLocation: 'inlineScript'
inlineScript: |
echo "Validating alert: ${{ alert.alertName }}"