0
votes

I have some problems with syntax, but it looks good. I can't find the mistake

trigger: none

pool:
  vmImage: 'ubuntu-18.04'

parameters:
  - name: themeNames
    values:
      - '1'
      - '2'
      - '3'

stages:
- stage: dev
  displayName: Dev
  jobs:
  - job: Deploy
    steps:
    - ${{ each parameter in parameters.themeNames }}:
      - template: build.yml
        parameters:
          themeName: ${{ parameter }}

what is wrong? enter image description here

now I use a solution like this, but I don't like it

stages:

  • stage: dev displayName: Dev jobs:
    • job: Deploy steps:
      • template: build.yml parameters: themeName: '1'
      • template: build.yml parameters: themeName: '2'
      • template: build.yml parameters: themeName: '3'
2

2 Answers

1
votes

My solution: run pipe with one parameter is to use a type object.

pool:
  vmImage: 'ubuntu-18.04'

parameters:
- name: themeNames1
  type: object
  default: 
   - 1
   - 2
   - 3


stages:
- stage: dev
  displayName: Dev
  jobs:
  - job: Deploy
    steps:
    - ${{ each parameter in parameters.themeNames1 }}:
      - bash: echo " ${{ parameter }}"

enter image description here

It works properly but ADO still complains about syntax. But if save it and run. It works...

enter image description here

0
votes

Please divide the value of themeNames into three different parameters. Otherwise, themeNames has only one value when you run the pipeline. Here is my sample:

azure-pipelines.yml:

parameters:
- name: themeNames1
  default: 1
- name: themeNames2
  default: 2
- name: themeNames3
  default: 3


stages:
- stage: dev
  displayName: Dev
  jobs:
  - job: Deploy
    steps:
    - ${{ each parameter in parameters }}:
      - template: build.yml
        parameters: 
          themeName: ${{ parameter.value }}

build.yml:

parameters:
- name: themeName
  default: ''
steps:
- script: echo ${{ parameters.themeName }}

Result:

enter image description here

You can also refer to the document about loop through parameters and template.