I’m building a release pipeline in Azure Devops. In one of the steps I’m using an inline bash script to retrieve the value of a secret previously retrieved by a KeyVault step.
This is the script:
#!/bin/bash
# Get the comma-separated list of connected systems from the pipeline variable
connected_systems=$(echo "$(connectedSystems)")
echo "${connected_systems}"
# Loop through each connected system
IFS=',' read -r -a connected_systems_array <<< "$connected_systems"
for connected_system_name in "${connected_systems_array[@]}"; do
# Get the password value from the corresponding pipeline variable
password="${!connected_system_name}"
echo "connected_system_name: ${connected_system_name}"
echo "password: ${password}"
# Replace placeholder with password in the file
sed -i "s/.password=placeholder/.password=$password/g" $(propertiesFile)
done
echo "$(propertiesFile)"
cat $(propertiesFile)
My problem is that I can’t find the way to actually retrieve the value from the pipeline variable with the name of ${connectedSystem}.
I’ve tried:
password=$(${connected_system_name}) -> Doesn't work
password=$(eval echo "${connected_system_name}") -> Doesn't work
password=$(eval "${connected_system_name}") -> Doesn't work
I’m running out of ideas as I thoght I would just need to pass the string value to the $() function to retrieve the value of the pipeline variable…
Any ideas?
Thanks in advance!
2
Answers
In order to retrieve values from the Azure Devops release pipeline variables you need to use the syntax here-
$(variablename)
I have updated your code to get the value of connectedSystem like and its system’s password like below:-
Bash script:-
My Release pipeline variables:-
Output:-
Reference:-
Define variables – Azure Pipelines | Microsoft Learn
Complete bash script:-
If the ‘
connectedSystems
‘ is a secret in Azure key vault, the Azure Key Vault task will download the secret value as string and set it as a secret variable in the pipeline. The pipeline secret variable has the same (connectedSystems
) with the Azure key vault secret. The values of secret variables will be always masked as "***
" in the console logs for security in pipelines. See "Set secret variables".After the Azure Key Vault task, on the subsequent steps within the same job, you normally can directly reference the secret variables using the expression "
$(varName)
".However, on the script tasks (such as Bash, PowerShell, CmdLine, etc..), it is recommended to map the secret variables into environment variables and reference the environment variables in the scripts. For example.