Azure Devops Split using comma separated variable

457 views Asked by At

I am trying to split a variable based on delimiter to loop over it. Followed this feature https://learn.microsoft.com/en-us/azure/devops/release-notes/2022/sprint-209-update?tabs=yaml#add-support-for-string-split-function-in-yaml-template-expressions:~:text=%22True%22%0A%7D-,Add%20support%20for%20string%20split%20function%20in%20YAML%20template%20expressions,-YAML%20pipelines%20provide

Here is the sample template.yaml file

jobs:
- job: package_template_job
  dependsOn: build_template_job
  displayName: Package

  variables:
  - name: TemplateRepository
    value: $[ resources.repositories['templates'].name ]

  steps:
  - checkout: self
    clean: true

  - checkout: templates
    clean: true

  - ${{ each v in split(variables.vars, ',') }}:
    - script: |
        echo ${{ v }}
      displayName: Printing vars 

and here is the actual pipeline.yaml using the template

variables:
  vars: dev,npr

trigger:
  - master

pool:
  vmImage: ubuntu-latest

jobs:
  - template: templates/build-template.yml@templates
  - template: templates/package-template.yml@templates

When executing the pipeline the split does not work as intended. It does not split and nothing gets printed on echo ${{ v }}. It is just blank.

Can someone please help on identifying the issue here? I am looking to use variables instead of parameters.

0

There are 0 answers