azureazure-devopsyamlazure-pipelines

Azure pipeline expand each parameter when using template


I have the following setup, a template file, and a pipeline that extends the template. I am wondering is it possible to dynamically add all parameters to extends' parameter?

Template.yml

parameters:
- name: Location
  type: string
  default: 'eastus'

Washington.yml

parameters:
- name: Location
  type: string
  default: 'westus'

extends:
  template: Template.yml
  parameters:
    Location: ${{ parameters.Location }} 

I can do something like this but I think it doesn't work because the shadowed parameters variable will be used instead of root level parameters.

parameters:
- name: Location
  type: string
  default: 'westus'

extends:
  template: Template.yml
  parameters:
  - ${{ each param in parameters }}
    ${{ param.Name  }}: ${{ param.Value }}

Solution

  • This works for me:

    parameters:
    - name: Location
      type: string
      default: 'westus'
    
    extends:
      template: Template.yml
      parameters:
        ${{ each param in parameters }}:
          ${{ param.Key }}: ${{ param.Value }}
    

    So you had small syntax issues.

    It printed:

    enter image description here

    Assuming that template is:

    parameters:
    - name: Location
      type: string
      default: 'eastus'
    
    steps:
    - script: echo ${{ parameters.Location }}