In the following yaml stage (code given below), I am trying to convert parameter envList to specific env names. e.g. envList = "NameDevEnv, NameQAEnv, NameStageEnv, NameProdEnv"
I am trying to pass NameDevEnv, NameQAEnv, NameStageEnv and NameProdEnv to separate variable/parameters in yaml and then pass these name to templates so those envs are created with the given names.
Following code is not printing the correct value for variable one. i.e. I am expecting the last statement, echo $(one) to print NameDevEnv.
Please advise / assist. Thanks
stages:
- stage: preWork
jobs:
- job: convert_input
continueOnError: false
steps:
- script: |
htring="${{parameters.envlist}}"
echo $htring
IFS=', ' read -r -a array <<< "$htring"
echo "${array[0]}"
htringz="${array[0]}"
echo ${{ variables.one }} # outputs initialValue
echo $(one)
echo $htringz
## $htringz = $htring.split(",")[0]
displayName: first vairable pass
- bash: echo "##vso[task.setvariable variable=one;isOutput=true;]$htringz"
displayName: set new variable value
- script: |
echo ${{ variables.one }} # outputs initialValue
echo $(one)
As Microsoft's docs point out, passing a variable between tasks requires setting the isOutput=true parameter on the variable. What they don't really explain is how this shows up in bash in the subsequent tasks. There are two key points:
name: FOO.$(FOO.BAR) (as would be used in Powershell), you use the bash syntax ${FOO_BAR}.Example:
- task: Bash@3
name: FOO
displayName: Set a variable for passing between tasks.
inputs:
targetType: inline
script: |
#!/bin/bash
echo "##vso[task.setvariable variable=BAR;isOutput=true]foobar"
- task: Bash@3
displayName: Use a variable in another task.
inputs:
targetType: inline
script: |
#!/bin/bash
echo "\${FOO_BAR} is '${FOO_BAR}'"
The example will output:
${FOO_BAR} is 'foobar'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With