Issues fetching secrets from Azure Key Vault from Azure Pipelines

Arunim Sharma 0 Reputation points
2025-01-06T22:17:53.72+00:00

Hello All,

I have been trying to fetch Secret stored in Azure Key vault, for that I have created a generic template:

fetch-secrets.yml:

parameters:
  - name: vaultName
    type: string
  - name: secretName
    type: string
  - name: serviceConnection
    type: string

steps:
  - task: AzureKeyVault@2
    inputs:
      azureSubscription: '${{ parameters.serviceConnection }}'
      KeyVaultName: '${{ parameters.vaultName }}'
      SecretsFilter: '${{ parameters.secretName }}'
      RunAsPreJob: true.       

I am using this template in my azure-pipeline.yml file:

stages:
  - stage: Init
    displayName: Get initial values
    jobs:
      - template: templates/init/getvars.yml@cicd
      - job: FetchSecrets
        displayName: Fetch Secrets
        steps:
          - template: templates/fetch-secrets.yml@aot
            parameters: 
              vaultName: 'MyVaultName'
              secretName: 'Mysecretname'
              serviceConnection: 'Service-Connection-Secrets'
          - script: | 
              echo "##vso[task.setvariable variable=MY_ENV_VAR]$(Mysecretname)" 
            name: SetTokenName 
            displayName: Set MY_ENV_VAR Variable

I want to use MY_ENV_VAR in .npmrc file to authenticate login to the external repo.

Is this the right or standard way to do it? If not, could you please advice.

Not Monitored
Not Monitored
Tag not monitored by Microsoft.
41,408 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. VarunTha 10,925 Reputation points Microsoft Vendor
    2025-01-15T09:15:10.51+00:00

    Hi Arunim Sharma,
    Thank you for reaching out to us on the Microsoft Q&A forum.

    Azure DevOps is currently not supported in the Q&A forums.

    I recommend initiating a new discussion through the Developer Community

    Moderators are readily available there to assist you and provide guidance.

    Please don't forget to Accept answer and close this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.