We have variable group in Pipeline and it has below input
Input: Instance1,Instance2,Inastance3
Expected Output: Instance1 Instance2 Inastance3
We tried below YAML Code
trigger:
- main
pool:
vmImage: ubuntu-latest
variables:
- group: "DevInstanceList"
- name: InstancesList
value: $[variables.Instances]
steps:
- script: echo $(InstancesList)
- ${{ each env in split(variables.InstancesList, ',')}}:
- script: echo ${{ env }}
We tried to split using comma seperator and getting below error.
Error: syntax error: invalid arithmetic operator (error token is
".Instances")
Instance Defined in Library–> Group variable
Please share your thoughts
2
Answers
You could try a powershell task like:
Note: A space between double quotes in split function.
Updated Answer: I Tested the code it works:
Adding variablegroup Image FYR:
Adding Results Image FYR:
Based on my test, the $[] cannot be fetched in compile time use for each. As @Daniel mentioned. If you are using ‘$(Instances)’ in "each", you will find the empty.
For more information, you can refer to Runtime expression syntax.
So you can try to provide the value in the YAML file.
YAML like: