I have following tasks in a pipeline (Azure DevOps). First task read a secret from a KeyVault using a variable $(mySecretName) which value is secret-name. Second task needs to pass the value of the read secret to a ARM:
- task: AzureKeyVault@2
displayName: 'Read secret'
inputs:
azureSubscription: $(mySubscription)
KeyVaultName: $(myKeyVault)
SecretsFilter: $(mySecretName)
RunAsPreJob: false
- task: AzureResourceGroupDeployment@3
displayName: 'Use secret value'
inputs:
resourceGroupName: $(myResourceGroup)
location: $(myLocation)
azureResourceManagerConnection: $(mySubscription)
templateLocation: 'Linked artifact'
csmFile: '$(Pipeline.Workspace)/cd-template.json'
overrideParameters: >
-secretValue "$($(mySecretName))"
deploymentMode: 'Incremental'
In line -secretValue "$($(mySecretName))" I'm trying to resolve in this way but apparently it does not work: $(mySecretName) -> $(secret-name) -> secret value. If I use $(secret-name) it will work, but I need to use $(mySecretName) because the name will change depending on the environment.
Is there any solution that allows me to get the value of a variable which name is the value of another variable?
From your YAML sample, you are using nested variables $($(mySecretName)). It is not yet supported in the pipelines.
To achieve your requirement, you can use the Variable Set task from extension: Variable Toolbox.
You can add the Variable Set task before the AzureResourceGroupDeployment task.
For example:
steps
- task: VariableSetTask@2
displayName: 'Set variable: kevin to: ''$($(test))'''
inputs:
variableName: NewVariable
Value: '$($(mySecretName))'
- task: AzureResourceGroupDeployment@3
displayName: 'Use secret value'
inputs:
resourceGroupName: $(myResourceGroup)
location: $(myLocation)
azureResourceManagerConnection: $(mySubscription)
templateLocation: 'Linked artifact'
csmFile: '$(Pipeline.Workspace)/cd-template.json'
overrideParameters: >
-secretValue "$(NewVariable)"
deploymentMode: 'Incremental'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With