How to get Secret URI instead of actual secret using AzureCLI@2 Task, to set in Configuration Settings and Ubuntu Agent

Viewed 20

Currently trying to get the Azure Key Reference from Key Vault using a DevOps Task.

I have it working for PowerShell but I was moved over to a different agent and now we are using PSCore for the script type. In doing so the previous way no longer works.

How do I do the following with PSCore as a scriptType?

          - task: AzureCLI@2
        displayName: 'Get KeyVault Secret URIs'
        inputs:
          azureSubscription: '$(Sub_Dev)'
          scriptType: 'ps'    
          failOnStandardError: true                  
          scriptLocation: 'inlineScript'
          inlineScript: |
           $Dev_keyVaultName= "$(AppService_Dev)"

                       

           $secretNames=(
                          "ServiceBusConnectionStringKey")
            $outputVars=(
                          "ServiceBusConnectionStringKey")
            $x=0
            while ($x -lt $secretNames.count)
            {
                  $uri=$(az keyvault secret show --vault-name $Dev_keyVaultName --name $secretNames.get($x) --query id --output tsv)
                  $secretname = $outputVars.get($x)                          
                  echo "##vso[task.setvariable variable=$secretname;]@Microsoft.KeyVault(SecretUri=$uri)"                          
                  $x++                          
            } 

This will loop through all the specified Keys that I send it and return the Reference to the Key, so that I can store the Reference in the Config instead of the actual Secret. Using the Next section it will return the actual Secret, but I need the reference?

- task: AzureCLI@2
        displayName: 'Get KeyVault Secret URIs'
        inputs:
          azureSubscription: '$(Sub_Dev)'
          scriptType: 'pscore'    
          failOnStandardError: true                  
          scriptLocation: 'inlineScript'
          inlineScript: |
           $Dev_keyVaultName= "$(AppService_Dev)"

          $(sbConnstring)=$(az keyvault secret show --name "ServiceBusConnectionStringKey" --vault-name $Dev_keyVaultName)
           
0 Answers
Related