azureazure-pipelines

How do I use azure secret variables in a yaml pipeline


I am trying to retrieve azure secret variables in a pipeline but for some reason I am not getting the values. So far I have setup the secrets in Azure

enter image description here

And added the variables

enter image description here

So in the pipline the service connection has been created

enter image description here

Then the variable group is created and linked to the azure Key vault

enter image description here

And permissions are set

enter image description here

And the actual pipeline itself we have

pool:
  vmImage: 'ubuntu-20.04'

steps:
  - task: AzureKeyVault@2
    displayName: Azure Key Vault
    inputs:
      azureSubscription: 'TestSecrets'
      KeyVaultName: 'SpiceKVT'
      SecretsFilter: 'UserId'
      RunAsPreJob: false
    env: 
      uid: $(UserId)

  - task: PowerShell@2
    displayName: Show UserId
    inputs:
      targetType: 'inline'
      script: 'Write-Host "User Login is $(uid)"'

But all I get is an empty value in $(uid), any ideas on what I am missing please


Solution

  • @Alvin Zhao - Even I was facing the same issue , how to print the actual value of the secret in Powershell as it showing *. In Powershell script, added the below but still its showing *** values for the secret.

    $keyVaultValue = Get-AzKeyVaultSecret -VaultName "xxx" -Name "DBPass" - AsPlainText

    Write-Host "Value of Value": $keyVaultValue

    --Output

    $keyVaultValue - ***

    2. Also tried the below facing same issue showing ***

    #$secret = (Get-AzKeyVaultSecret -VaultName "XXX" -Name "DBPass").SecretValueText