Search code examples
azure-devopsazure-pipelinesazure-pipelines-yaml

Azure pipeline parameter split doesn't work


I have a mutli-step azure pipeline used to trigger the execution of a certain job based on keywords I have in azure devops work items. First step executed is a powershell script that stores into a 'validTags' variable a comma-separated list of strings:

Write-Host "##vso[task.setvariable variable=validTags]$csTags"

After this step, I correctly see the list formatted as I expect:

string1,string2,string3

The 'validTags' variable is then passed as a parameter to another pipeline in which I should split this list and trigger separate jobs:

- template: run.yml
    parameters:
      tags: $(validTags)
      directory: 'path\to\tests'
      platforms: 'platform1,platform2'

In the 'run' pipeline I defined this 'tags' parameter:

parameters:
- name: tags
  type: string
  default: 'someDefaultValue'

and I try to split the parameter:

- ${{each t in split(parameters.tags, ',')}}:
    - script: |
        echo 'starting job for ${{t}}'

but when I execute the pipeline, I have in 't' still the full string (string1,string2,string3) not splitted.

I have noticed that if I try to perform the split on the "platforms" parameter which is passed along with "tags" to the run.yml pipeline, it works, so it seems that the problem is related to the fact that I am trying to split a string stored in an external variable?

Anyone with a similar issue? Any help on this is much appreciated.

Thanks


Solution

  • For those interested in the outcome of this issue:

    • I tested several possible alternate solutions, including the use of global variables and group variables, but without success.

    • I submitted a request to MSFT engineering support to get some insight on this and their response is:

    The pipeline does not support splitting the runtime variable with template syntax ${{ }} currently, and we are not able to find other workarounds to meet your request. Sorry for the inconvenience. Hope you can understand.

    So, to overcome the issue I removed the split at the pipeline level, as initially planned, but rather passed the comma-separated value's string to the template and added there the necessary processing in Powershell.

    Another option would have been to perform all the operations from within the first PowerShell script step:

    • transform the 'run.yml' template in a separate pipeline
    • in the script, after getting the tags, loop over their values and trigger the 'run.yml' pipeline passing the single tag as a parameter. I avoided this solution to keep the operations separate and have more control over the execution flow.