azure-devopsazure-cli2

In Azure Devops yaml, I am unable to use pipeline variables in a "Azure CLI task v.2"


I am unable to use pipeline variables from the AzureCLI@2 task. In the yml below, thing2 outputs as expected, but thing does not output anything at all. Why doesn't thing output and how do I use AzureCLI@2 to set variables in the pipeline?

stages:
  - stage: Deploy
    pool:
      vmImage: 'windows-latest'
    jobs:
    - deployment: 'Deploy1'
      environment: 'dev'
      strategy:
        runOnce:
          deploy:
            steps:
            - task: AzureCLI@2
              displayName: 'output'
              inputs:
                azureSubscription: Subscription
                scriptType: 'pscore'
                scriptLocation: 'inlineScript'
                addSpnToEnvironment: true
                inlineScript: |
                  echo "##vso[task.setvariable variable=thing;isOutput=true]thing"
            - powershell: |
                echo "##vso[task.setvariable variable=thing2;isOutput=true]thing2"
              name: output2
            - powershell: |
                $ErrorActionPreference = 'SilentlyContinue'
                Write-Host thing - $(output.thing) #doesnt work
                Write-Host thing2 - $(output2.thing2) #works

Solution

  • displayName isn't the same thing as name. You're not naming your AzureCLI@2 step to be output.