Reputation: 2417
I have a Bash script in my build pipeline that will set some build variables depending on which branch triggered The build. However when I try to echo these variables in another bash script some of them don't echo.
Set Environment Variables:
if [[ $(Build.SourceBranchName) == 'develop' ]]; then
echo $TagVersion
echo $(Build.BuildId)
echo '##vso[task.setvariable variable=AppVersion;]$TagVersion'
echo '##vso[task.setvariable variable=ChangeSet;]$(Build.BuildId)'
echo '##vso[task.setvariable variable=Environment;]DEVTEST'
echo '##vso[task.setvariable variable=BuildConfig;]Debug'
fi
This has a output of:
v1.4.0
7090
Set Version:
echo $(AppVersion)
echo $(ChangeSet)
echo $(Environment)
echo $(BuildConfig)
This outputs
7090
DEVTEST
Debug
Why is the AppVersion now writing to the console?
Upvotes: 0
Views: 451
Reputation: 8343
The $()
syntax is evaluated by the Agent before bash sees it, while the $
var is evaluated by bash. This is why ChangeSet is correctly assigned.
The echo '##vso[task.setvariable variable=AppVersion;]$TagVersion'
command uses a single quote ('
) which stops bash from interpreting the content. To expand the variable use a double quote ("
), that is echo "##vso[task.setvariable variable=AppVersion;]$TagVersion"
Upvotes: 1