I have an issue using Azure Vault to store my secrets and .properties file to store the secret name (so it is not hardcoded in the pipeline) and access it later from the Azure DevOps Pipeline: .properties file:
...
SERVER_ADMIN_SECRET_NAME=server-password-test
...
I am using template pipeline which reads the file and exports all key=values as $(property) with corresponding value as a global property (##vso[task.setvariable variable=$KEY]$VAL
).
When I call Azure Key Vault, it returns the key name and export variable $(server-password-test)
so it can be used later. However, I am unable to access it, because the variable name is the value of another variable $(SERVER_ADMIN_SECRET_NAME)
. The solution should be using a variable inside variable $($(SERVER_ADMIN_SECRET_NAME))
, but this does not work in Azure Pipelines.
My pipeline looks like this:
...
- template: read_properties.yml
parameters:
file: config.properties
- task: AzureKeyVault@1
inputs:
azureSubscription: 'vault-service-connection'
KeyVaultName: 'test-playground'
SecretsFilter: '$(SERVER_ADMIN_SECRET_NAME)'
# TODO : How to fix this??
- task: CmdLine@2
inputs:
script: |
echo $($(SERVER_ADMIN_SECRET_NAME))
...