Search code examples
azurepowershelldevopsjqazure-cli

unable to execute the command the jq command in azure devops pipeline


I have this command where I am trying to validate whether managed identity is already assigned to a particular resource or not. I am getting the managed identity dynamically so, I am keeping it as pipeline variable. when I run this command on azure portal by opening the cli, its running successfully.

$test = "name"
az vmss identity show -g group-name -n vmss-name -o json | jq '.userAssignedIdentities | with_entries(select(.key | contains("$test")))'

when I run the exact same command in the pipeline I am getting error.

jq: error: $test is not defined at , line 1:

here is the task

- task: AzureCLI@2
          inputs:
            azureSubscription: $(sub)
            scriptType: 'pscore'
            scriptLocation: 'inlineScript'
            inlineScript: |
               az vmss identity show -g group-name -n vmss-name -o json | jq '.userAssignedIdentities | with_entries(select(.key | contains("$test")))'

        azurePowerShellVersion: 'latestVersion'

Solution

  • Thanks @pmf. Here is the updated command.

    az vmss identity show -g group-name -n vmss-name -o json | jq --arg test "$test" '.userAssignedIdentities | with_entries(select(.key | contains($test)))'