Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using nested parameters with template in Azure Pipelines yaml file

Is there any way to use nested within parameters on azure-pipelines.yml? The example below is wrong...

# my-template.yml
parameters:
steps:
- ${{ each pf in parameters.pf }}:
  - task: PublishBuildArtifacts@1
    displayName: 'Publish ${{ pf.rid }} ${{ pf.output }}'
    inputs:
      PathtoPublish: '$(Build.ArtifactStagingDirectory)/${{ pf.output }}.zip'
# azure-pipelines.yml
steps:
- template: my-template.yml
  parameters:
  - windows:
      rid: 'win-x64'
      output: 'Foo.exe'
  - macos:
      rid: 'osx-x64'
      output: 'foo'
like image 468
idubnori Avatar asked Jan 22 '26 08:01

idubnori


1 Answers

I tweaked your example a little bit to make it work:

# my-template.yml
parameters:
  pf: []

steps:
- ${{ each pf in parameters.pf }}:
  - script: echo ${{ pf.rid }} ${{ pf.output }}
    displayName: 'Publish ${{ pf.rid }} ${{ pf.output }}'
# azure-pipelines.yml
steps:
- template: my-template.yml
  parameters:
    pf:
    # windows
    - rid: 'win-x64'
      output: 'Foo.exe'
    # macos
    - rid: 'osx-x64'
      output: 'foo'

You could find more information here about templates iterative insertion.

Although I suspect what you want to do could be better achieved using strategy and matrix like the following:

# azure-pipelines.yml
strategy:
  matrix:
    windows:
      imageName: "vs2017-win2016"
      output: 'Foo.exe'
    macos:
      imageName: 'macos-10.13'
      output: 'foo'

pool:
  vmImage: $(imageName)

steps:
- script: echo $(output)
  displayName: 'Publish'

You could find more information here about build across multiple platforms.