Within Azure DevOps YAML is it possible to use a variable within a get for another variable.
my specific issue is around using the Azure Key Vaults task. using this task as below:
- task: AzureKeyVault@1
displayName: 'Get Secrets $(KeyVault_Key) from ${{parameters.KeyVaultName}}'
inputs:
azureSubscription: ${{parameters.azureSubscription}}
KeyVaultName: ${{parameters.KeyVaultName}}
SecretsFilter: '$(KeyVault_Key)'
RunAsPreJob: true
I have a variable in the Library called KeyVault_Key and pass this into the filter.
The Key Vault task will create a new variable using the value of this variable.
e.g. if KeyVault_Key = "mySecretKey" then it create a variable you can access as $(mySecretKey)
However, when trying to access all of this using the variable commands it does not work.
e.g. $($(KeyVault_Key))
I have also tried variables as well like
e.g. $(${{variables.KeyVault_Key}})
** Update **
This is an example using the variable solution as recommended.
- stage: 'Deploy'
displayName: 'Deploy Application'
variables:
- name: "sqlConnectionNameKey"
value: '$(TF_VAR_MYSQL_SERVER_USERNAME_KEY)'
- name: "sqlConnectionPwdKey"
value: '$(TF_VAR_MYSQL_SERVER_PASSWORD_KEY)'
jobs:
- deployment: DeployApiDatabase
pool:
name: Default
environment:
name: Azure
strategy:
runOnce:
deploy:
steps:
- task: AzureKeyVault@1
displayName: 'Get Secrets'
inputs:
azureSubscription: ${{parameters.azureSubscription}}
KeyVaultName: '$(TF_VAR_RESOURCE_PREFIX)-kv'
SecretsFilter: '${{variables.sqlConnectionNameKey}}, ${{variables.sqlConnectionPwdKey}}'
RunAsPreJob: true
- task: AzureMysqlDeployment@1
displayName: 'Deploy ApplicationConfigurationDbContext DB'
inputs:
azureSubscription: ${{parameters.azureSubscription}}
ServerName: '$(sqlServerName).mysql.database.azure.com'
DatabaseName: 'DatabaseName'
SqlUsername: '$(sqlConnectionNameKey)@$(sqlServerName)'
SqlPassword: '$(sqlConnectionPwdKey)'
TaskNameSelector: 'SqlTaskFile'
SqlFile: '${{variables.mySqlLocation}}DbContext.sql'
IpDetectionMethod: 'AutoDetect'