jcgh582
jcgh582

Reputation: 909

Use Variable from Variable Group in bash script on VSTS

I have linked a variable group to my build pipeline. The variable group has a variable in it. I am trying to use the variable in a bash script in my pipeline.

This document describes how to reference my variable from my variable group:

[https://learn.microsoft.com/en-us/vsts/pipelines/process/variables?view=vsts&tabs=yaml%2Cbatch][2]

However, $TESTING_YOLO does not work.

I have spent 2 hours trying to reference this variable from a bash script. Literally no idea how to do it.

Upvotes: 5

Views: 5235

Answers (2)

Marina Liu
Marina Liu

Reputation: 38136

The format to use the variables from variable group which links Azure key value as below:

$(VariableName)

Such as you can use the format $(yolo). But since the variable yolo is secret, the value will be marked as *** from the build logs.

Upvotes: 3

jcgh582
jcgh582

Reputation: 909

I have figured out that variables in my variable group that come from key vault are not visible in my env variables when running the bash script.

Further, if I create a variable group that is not linked to key vault i.e. a variable group with key: value, yolo1: yolo1, those variables are visible in my env variables when running the bash script.

To summarise this update, variables in a variable group that come from key vault don't work as expected.

"However, secret variables (encrypted variables and key vault variables) cannot be accessed directly in scripts - instead they must be passed as arguments to a task". Quoted from here: https://learn.microsoft.com/en-us/vsts/pipelines/library/variable-groups?view=vsts

So we had to figure out how to pass arguments to our task. Here I am passing my secret yolo3 as an argument to my bash script task

Pass yolo3 argument to our tasks

Then I can reference the secret yolo3 as an argument in my bash script i.e. $1.

Hopefully, this will help someone else :).

Upvotes: 4

Related Questions