Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
419 views
in Technique[技术] by (71.8m points)

Azure DevOps Yaml: Gaining secret variable out of Azure KeyVault Task from Variable

I'm trying to obtain a secret out of my KeyVault. The variable name is secretVar.

Obtaining the secret like this: $(secretVar) works fine however I would like to retrieve it from a variable like this:

enter image description here

I keep getting command not found and I've no idea why this shouldn't be working.

So the name of the secret I want to extract is inside a bash variable. For this question I've simplified the problem but in my real use case I have a bash for loop which loops through secret names and inside the for loop I want to extract the appropriate value from the KeyVault with the corresponding secret name like this:

for secretname in secrets; do
  echo $($secretname) # This should contain the value of the secret but gives command not found
done

If anyone has an idea what could be happening, any help is very appreciated.

Thanks in Advance!

question from:https://stackoverflow.com/questions/65644007/azure-devops-yaml-gaining-secret-variable-out-of-azure-keyvault-task-from-varia

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Look at the syntax you're using.

variable=secretVar

You are creating an environment variable with the literal value secretVar

Then you try to execute the value of the variable $variable with $($variable). So it tries to run the command secretVar, which obviously doesn't exist, and you get an error message.

The syntax you're looking for is

variable=$(secretVar)

just like you used in the first echo command in the script.

If you don't want to run the variable value as a command, the syntax would be $variable, not $($variable)

$variable is the syntax for a Bash environment variable.

$(variable) is the syntax for referencing Azure DevOps variables.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...