Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass a list of string parameters to an Azure DevOps template

In a previous SO question, I was trying to get create an Azure DevOps template.

Now that I know how to do that, I'm trying to pass in a list of strings to the template and use them in the template, like so:

azure_pipelines.yml

extends:
  template: AzurePipelines/job.yml
  parameters:
    projects:
      - FirstProject.csproj
      - SecondProject.csproj

and in this template...

job.yml

steps:
 (for each projectFileName in projects)
 - bash echo $(projectFileName)
 - run code in the build.yml template using $(projectFileName)
 - run code in the test.yml template using $(projectFileName)
 - run code in the publish.yml template using $(projectFileName)

So for each project name handed into the template, run the template steps.

I'm not sure how to pass in an array of strings and how to test that it works?

like image 570
Pure.Krome Avatar asked Oct 20 '25 10:10

Pure.Krome


1 Answers

It seems you are looking for each function:

# my-template.yml
parameters:
- name: 'projects'
  type: object
  default: []
steps:
- ${{ each project in parameters.projects }}:
  - task: PublishBuildArtifacts@1
    displayName: 'Publish ${{ project }}'
    inputs:
      PathtoPublish: '$(Build.ArtifactStagingDirectory)/${{ project }}.zip'
# ci.yml
steps:
- template: my-template.yml
  parameters:
    projects:
    - test1
    - test2
like image 129
Cece Dong - MSFT Avatar answered Oct 22 '25 01:10

Cece Dong - MSFT



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!