Getting secret value from keyvault RRS feed

  • Question

  • Hello Team,

    I have a requirement wherein:

    1) I have a variable declared in the pipeline. I want to assign the variable a value which a secret value from the key vault

    Is there any way by which I can fetch the secret value from key vault and assign it to the variable?

    Friday, June 21, 2019 5:56 AM

All replies

  • Hi Nandan,

    Yes, it can certainly be done. A few ways to do so are as follows :

    • Using an Azure Function / Function App / Custom activity - you can have an Azure Function activity or a function app to retrieve the secret value using Azure Key Vault SDK. You can then chain a set variable activity to store the value returned from the Azure Function / Function App. Here's the code to fetch a secret :

                 /* The next four lines of code show you how to use AppAuthentication library to fetch secrets from your key vault */
                 AzureServiceTokenProvider azureServiceTokenProvider = new AzureServiceTokenProvider();
                 KeyVaultClient keyVaultClient = new KeyVaultClient(new KeyVaultClient.AuthenticationCallback(azureServiceTokenProvider.KeyVaultTokenCallback));
                 var secret = await keyVaultClient.GetSecretAsync("https://<YourKeyVaultName>")
                 Message = secret.Value;
             /* If you have throttling errors see this tutorial */
             /// <exception cref="KeyVaultErrorException">
             /// Thrown when the operation returned an invalid status code
             /// </exception>
             catch (KeyVaultErrorException keyVaultException)
                 Message = keyVaultException.Message;

    Ref -

    PS : You can do the same using NodeJS too, please refer this doc.

    Friday, June 21, 2019 9:27 AM
  • Hi Nandan,

    Was your query resolved with the above suggestion ? If yes, please consider upvoting and/or marking as answer as it would benefit others reading this thread.
    Monday, June 24, 2019 6:52 AM