How to pass the secret from azure key vault to Environmental variable
The environmental variable TEST_SECRETS shall contain the secrets from the azure key vault. This can be achieved by the AzureKeyVault task shown as follow
- task: AzureKeyVault@2
displayName: Credential Fetch
inputs:
connectedServiceName: 'KVfetch'
KeyVaultName: 'kv_abc_devops'
SecretsFilter: 'db-primarykey-dev'
RunAsPreJob: true
How can I pass the value of db-primarykey-dev to TEST_SECRETS
can I use variables as follows?
variables:
- name: TEST_SECRET
value: $db-primarykey-dev
I try to pass the variable right before the test it does not work
- task: CmdLine@2
displayName: Integration Tests
- script: |
echo 'TEST_SECRET = $db-primarykey-dev'
pytest test/integration --verbose -s
You can do this using env mapping:
- task: CmdLine@2
displayName: Integration Tests
- script: |
pytest test/integration --verbose -s
env:
TEST_SECRET: $(db-primarykey-dev)
Also please check and try by specifying the azureSubscription field under inputs of azurekeyvault task if it makes difference byreplacing Connected service name or by including as additional parameter:
azureSubscription: 'YOUR SUBSCRIPTION HERE'
Try with > echo $(TEST_SECRET) . See this doc for reference. See if you are missing inputs tag in
- task: CmdLine@2
displayName: Integration Tests
inputs:
script: echo $(TEST_SECRET)
See the reference. Also we can do environment mapping as said by @Krzysztof Madej