Using each loop on a task in Azure DevOps

Viewed 77

Actually I'm trying to repeat a task on Azure DevOps Pipeline a set of objects that are defined in paramaters field as below:

parameters:
- name: container-names
  displayName: a list of choices
  type: object
  default:
    - appName1
    - appName2
    - appName3
    - appName4

Now what I would like to do is to provide the name of these apps in an ansible@0 as follow:

  - stage: TST
    displayName: 'Deploy TST'

    jobs:
      - job: download_and_execute_playbook
        pool:
          name: 'CDaaSLinux'

        steps:

          ...
          ...
          ...

        - ${{ each container in parameters.container-names }}:          
          - task: Ansible@0
            inputs:
              ansibleInterface: 'agentMachine'
              playbookPathOnAgentMachine: '$(System.DefaultWorkingDirectory)/ansible/site_main.yaml --limit test -vvv --extra-vars "service=${{ container }}"'
              inventoriesAgentMachine: 'file'
              inventoryFileOnAgentMachine: '$(System.DefaultWorkingDirectory)/ansible/hosts.yaml'

It looks like it can be achieved regarding the documentation but I get this error message when trying to implement it:

enter image description here

/pipelines/stop-start.yaml (Line: 118, Col: 13) Unexpected symbol 'container-names'. Located at position 12 within expression: parameter.container-names

Any help would be appreciated

1 Answers

You need to use a different syntax if your parameter or variable name contains special characters like - or .: parameters['container-names'].

Related