I'm struggling with the syntax of the each
keyword in YAML templates.
Essentially, I'm passing a list of jobs to a template. The template should execute those jobs, filtering out unwanted variable groups.
template.yml:
parameters:
- name: DeployJobs
type: jobList
jobs:
- ${{ each job in parameters.DeployJobs }}:
${{ if job.variables }}:
variables:
- ${{ each var in job.variables }}:
- ${{ each pair in var }}:
${{ if ne(pair.value, 'var-group-blue') }}:
- group: ${{ pair.value }}
azure-pipelines.yml:
jobs:
- template: template.yml
parameters:
DeployJobs:
- deployment: mydeployjob
variables:
- group: var-group-blue # the template should filter out this var group
- group: var-group-green
...
But I'm getting the compilation errors Expected a mapping
and Object reference not set to an instance of an object.
on the line:
- group: ${{ pair.value }}
Can anyone offer advice on what syntax or indenting that I may be missing?
I figured it out. I was missing a dash on the if
clause. The specifics of when to use dashes and how much to indent are extremely arcane and poorly documented in the docs.
Working solution:
# template.yml
parameters:
- name: DeployJobs
type: jobList
jobs:
- ${{ each job in parameters.DeployJobs }}:
${{ if job.variables }}:
variables:
- ${{ each var in job.variables }}:
- ${{ each pair in var }}:
- ${{ if ne(pair.value, 'var-group-blue') }}:
- group: ${{ pair.value }}
# azure-pipelines.yml
jobs:
- template: template.yml
parameters:
DeployJobs:
- deployment: mydeployjob
variables:
- group: var-group-blue # the template should filter out this var group
- group: var-group-green
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With