user3417479
user3417479

Reputation: 1910

Azure Devops yaml - Runtime variable doesn't not behave like compile time variable

In Azure Devops I am using the template yaml loop-template.yml:

parameters:
  paths: string

steps :

  - ${{ each path in split(parameters.paths, ',') }}:
  - script: echo "loop template " ${{ path }}
    displayName: ScriptName ${{ path }}

which gets a comma-delimited string with paths and tries to iterate through them.

I call this template from another yaml which is like this

variables:
- name: SnykScanPaths
  value: val1,val2

        # it doesn't work
      - template: loop-template.yml
        parameters: 
          paths : $(SnykScanPaths)

        # it works
      - template: loop-template.yml
        parameters: 
          paths : ${{variables.SnykScanPaths}}

The results I get are the following

enter image description here

So even though the compile time variable ${{variables.SnykScanPaths}} has the same value with run time variable $(SnykScanPaths), only the compile time variable leads to proper iteration.

Any idea what can I do with this? thanks for the help.

Upvotes: 1

Views: 370

Answers (1)

Bowman Zhu
Bowman Zhu

Reputation: 7241

This is expected.

You must use ${{}} as the structure to get the value, if you use $(), the entire string will be recognized as string by default.

Parameter Usage

Parameters are expanded just before the pipeline runs so that values surrounded by ${{ }} are replaced with parameter values.

So simply put, your first type of usage is not correct.

Upvotes: 1

Related Questions