title: Unable to run az pipeline commands within Azure DevOps Task
body: <p>Trying to dynamically retrieve all the variables from a variable group via Azure DevOps task in a YAML Pipeline. Originally tried leveraging the AzureCLI@2 task with the following code to retrieve the variableGroupID which would be used to get the variables inside of it:</p>
  <pre><code>$variableGroupId = $(az pipelines variable-group list --org $(System.CollectionUri) --project $(System.TeamProject) --query &quot;[?name=='{{ parameters.variableGroupName }}'].id&quot; -o tsv)
  </code></pre>
  <p>This command works locally but not when executing on a MS hosted agent like this:</p>
  <pre><code>parameters:
    variableGroupName: ''
  
  steps:
  - task: AzureCLI@2
    displayName: Azure CLI
    inputs:
      azureSubscription: ${{ parameters.azureSubscriptionName }}
      scriptType: pscore
      scriptLocation: inlineScript
      inlineScript: |
        az upgrade
        $variableGroupId = $(az pipelines variable-group list --org $(System.CollectionUri) --project $(System.TeamProject) --query &quot;[?name=='{{ parameters.variableGroupName }}'].id&quot; -o tsv)
        write-Host $variableGroupId
        $variables = $(az pipelines variable-group variable list --group-id $variableGroupId  --org $(System.CollectionUri)  --project $(System.TeamProject) -o yaml)
        write-Host $variables
  </code></pre>
  <p>This fails with the error:</p>
  <pre><code>Before you can run Azure DevOps commands, you need to run the login command (az login if using AAD/MSA identity else az devops login if using PAT token) to setup credentials. Please see https://aka.ms/azure-devops-cli-auth for more information
  </code></pre>
  <p>I have opened up an <a href="https://github.com/Azure/azure-cli-extensions/issues/2935" rel="nofollow noreferrer">issue</a></p>
  <p>In the meantime, I tried to run the <a href="https://docs.microsoft.com/en-us/azure/devops/cli/azure-devops-cli-in-yaml?view=azure-devops" rel="nofollow noreferrer">commands to install the necessary pieces via scripts</a></p>
  <pre><code>   strategy:
        runOnce:
          deploy:
            steps:
            - task: AzureRmWebAppDeployment@3
              inputs:
                azureSubscription: Example - Dev
                WebAppName: wapp-Example-dev-eus
                Package: $(Pipeline.Workspace)/drop/Web.Example.zip
                TakeAppOfflineFlag: True
            - task: UsePythonVersion@0
              inputs:
                versionSpec: '3.x'
                architecture: 'x64'
            - task: CmdLine@2
              displayName: 'Upgrade pip'
              inputs:
                script: python -m pip install --upgrade pip
            - task: CmdLine@2
              displayName: 'upgrade azure cli'
              inputs:
                script: pip install --pre azure-cli --extra-index-url https://azurecliprod.blob.core.windows.net/edge
            - task: CmdLine@2
              displayName: 'Show Azure CLI version'
              inputs:
                script: az --version
            - task: CmdLine@2
              displayName: 'Install Azure DevOps Extension'
              inputs:
                script: az extension add -n azure-devops
            - task: CmdLine@2
              env:
                AZURE_DEVOPS_CLI_PAT: $(patCredential)
              displayName: 'Login Azure DevOps Extension'
              inputs:
                script: echo ${AZURE_DEVOPS_CLI_PAT} | az devops login
            - task: CmdLine@2
              displayName: 'Show List of Variables'
              inputs:
                script: |
                  $variableGroupId = $(az pipelines variable-group list --org $(System.CollectionUri) --project $(System.TeamProject) --query &quot;[?name=='{{ parameters.variableGroupName }}'].id&quot; -o tsv)
                  write-Host $variableGroupId
                  $variables = $(az pipelines variable-group variable list --group-id $variableGroupId  --org $(System.CollectionUri)  --project $(System.TeamProject) -o yaml)
                  write-Host $variables
  </code></pre>
  <p>However, when using both latest Ubuntu agents and those designated in the doc get an error:</p>
  <pre><code>WARNING: Failed to store PAT using keyring; falling back to file storage.
  WARNING: You can clear the stored credential by running az devops logout.
  WARNING: Refer https://aka.ms/azure-devops-cli-auth to know more on sign in with PAT.
  </code></pre>
  <p>I have opened up an <a href="https://github.com/MicrosoftDocs/azure-devops-docs/issues/10070" rel="nofollow noreferrer">issue with the documentation team</a> as at the very least the provided steps do not work. Any assistance would be appreciated!</p>