azure-pipelines-agent: Update environment variables using `task.setvariable` in a bash script does not work
I’m trying to update environment variables using a bash script. but the variables are not being udpated. Please see script below:
echo "version ~> $VERSION"
echo "build ~> $BUILD"
echo "##vso[task.setvariable variable=version;]2.0.0"
echo "##vso[task.setvariable variable=build;]20"
echo "Version ~> $VERSION"
echo "Build ~> $BUILD"
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 1
- Comments: 31 (9 by maintainers)
Commits related to this issue
- Another try, why does it works on Linux and not windows? https://github.com/microsoft/azure-pipelines-agent/issues/2018 — committed to mratsim/weave by mratsim 5 years ago
- Windows support (#59) * Fix side-effect tracking of memory pools * Implement windows barriers and common barrier API * Fix barriers API * Add affinity on windows * Skip perf measure on wi... — committed to mratsim/weave by mratsim 5 years ago
I have solved it in this way:
echo "##vso[task.setvariable variable=ACR_REGISTRY_LOGIN]$ACR_REG"
1.- With double quotes in echo command. 2.- Removing semicolon at the end of variable name.
Regards.
I cannot tell you how much this has saved my bacon 😃 amazing thank you!!
This does not work, I have also the same issue. This is happening in Bash@3 task in yaml pipeline.
@TingluoHuang @bryanmacfarlane It would be nice to update the documentation on this matter, I have myself spent a few hours trying to figure it out.
Both are working for me:
@TingluoHuang I am a bit tired of try things… 😉 In this way it runs.
@carvalho-oak
##vso[task.setvariable]
change the variables in the agent’s context, the change will show up in your following task. in your sample, if you add another bash script task and let it runprintenv|sort
, you will see your new $Build/$Version@ferpega
#
is comment in bash, you need to escape it.##vso[task.setvariable]
is a instruction to let the agent update its variable collection, so following task can consume the variable.the following should work. task1: echo ‘##vso[task.setvariable variable=ACR_REGISTRY_LOGIN;]$ACR_REG’ task2: echo $ACR_REGISTRY_LOGIN