title: Conditional Stage Execution in Azure DevOps Pipelines
body: <p>I want a stage in an Azure DevOps pipeline to be executed depending on the content of a variable set in a previous stage.</p>
  <p>Here is my pipeline:</p>
  <pre class="lang-yaml prettyprint-override"><code>stages:
    - stage: plan_dev
      jobs:
      - job: terraform_plan_dev
        steps:
        - bash: echo '##vso[task.setvariable variable=terraform_plan_exitcode;isOutput=true]2'
          name: terraform_plan
  
    - stage: apply_dev
      dependsOn: plan_dev
      condition: eq(stageDependencies.plan_dev.terraform_plan_dev.outputs['terraform_plan.terraform_plan_exitcode'], '2')
      jobs:
      - deployment: &quot;apply_dev&quot;
        ...
  </code></pre>
  <p>The idea is to skip the <code>apply_dev</code> stage, if the <code>plan_dev</code> stage shows no changes. Background is that we have manual approval for the deployment in the <code>plan_dev</code> stage that we want to skip if there are no changes to be approved.</p>
  <p>Unfortunately this doesn't seem to work. No matter whether the variable <code>terraform_plan_exitcode</code> is set with the expected value (2) or not, the <code>apply_dev</code> stage is skipped.</p>
  <p>For the syntax, I followed the <a href="https://docs.microsoft.com/en-us/azure/devops/pipelines/process/expressions?view=azure-devops#job-to-job-dependencies-across-stages" rel="nofollow noreferrer">documentation here</a> that says:</p>
  <pre><code>stageDependencies.StageName.JobName.outputs['StepName.VariableName']
  </code></pre>