title: Azure pipeline: how to use an output variable in a condition
body: <p>I am working on a pipeline running on a Windows Self Hosted agent.
  I need to call a script that initialize a variable in one stage and use the variable in a condition of the next stage.</p>
  <p>Here is my Yaml:</p>
  <pre><code>stages:
    - stage: Init
      jobs:
      - job: RunScript
        steps:
          - task: PowerShell@2
            name: compareFiles
            inputs:
              targetType: filePath
              filePath: '***\compareFileContent.ps1'
  
    - stage: DisplayStage
      dependsOn: Init
      variables:
        areFilesDifferent: $[ stageDependencies.Init.RunScript.outputs['compareFiles.areDifferent'] ]
      jobs:
      - job: Display
        steps:
          - script: |
              echo $(areFilesDifferent)
  
    - stage: DeploymentStage
      dependsOn: DisplayStage
      variables:
        areFilesDifferent: $[ stageDependencies.Init.RunScript.outputs['compareFiles.areDifferent'] ]
      condition: eq( '$(areFilesDifferent)', 'true' )
      jobs:
      - deployment: DeploymentJob
        environment: 'ATest'
        strategy:
          runOnce:
            deploy:
              steps:
                - checkout: none
                - task: CmdLine@2
                  inputs:
                    script: |
                      echo EnvName Finally: $(areFilesDifferent)
  </code></pre>
  <p>Here is my Powershell:
  '***\compareFileContent.ps1'</p>
  <pre><code>$equal = $filetext1 -ceq $filetext2 # case sensitive comparison
  $equalString = (&amp;{If($equal) {&quot;true&quot;} Else {&quot;false&quot;}})
  echo &quot;##vso[task.setvariable variable=areDifferent;isOutput=true]$equalString&quot;
  </code></pre>
  <p>The display job prints &quot;true&quot; but the stage condition always returns false.
  I tried with a function returning a boolean instead of a string, didn't work.
  I tried different syntax in the condition, always returns false.
  I tried moving the condition down to the first job but in that case the approval of the environment is triggered before the condition is evaluated.</p>
  <p>My goal is that the Powershell decides if that environement should be used.
  When environment is used, there is an approval step.</p>
  <p>I did wrote another post on this (<a href="https://stackoverflow.com/questions/67972610/azure-pipelines-question-about-variables-powershell-and-deployments">Azure pipelines, question about variables, powershell and deployments</a>), now I succeeded to retrieve the Output variable from the script but I still can't use it in a condition.</p>
  <p>Would you be able to help me ?</p>