0

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?

1
  • 1
    Where do you configure the $TagVersion value? Commented Jul 22, 2019 at 13:55

1 Answer 1

1

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"

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.