Rewiring

Azure Pipelines - setting a stage variable from another stage's output

I just can't stop stumbling on the difference between Azure Pipelines runtime ($[]) and compile time expressions (${{ }}). This bit me again when trying to set up a seemingly simple stage - stage dependency with conditions

The docs say that dependencies between stages should be done using the dependencies.STAGE.outputs['JOB.STEP.VARIABLE'] syntax. And fair enough, this works for conditions.

What it does not work for is variables. In order to set a variable from another stage's output, use $[ stageDependencies.STAGE.JOB.outputs['STEP.VARIABLE'] ]

This does not work:

  - stage: Debug
    dependsOn: DETERMINE_CHANGES
    condition: or(eq(dependencies.DETERMINE_CHANGES.outputs['backend.hasChanges.result'], 'true'), eq(${{ parameters.forceDeploy }}, true))
    variables:
      backend_changes: $[ dependencies.DETERMINE_CHANGES.outputs['backend.hasChanges.result'] ]
    jobs:
      - job: PrintVariables
        steps:
          - bash: |
              echo "Backend changes detected: $(backend_changes)"
            name: debugStep

This does:

  - stage: Debug
    dependsOn: DETERMINE_CHANGES
    condition: or(eq(dependencies.DETERMINE_CHANGES.outputs['backend.hasChanges.result'], 'true'), eq(${{ parameters.forceDeploy }}, true))
    variables:
      backend_changes: $[ stageDependencies.DETERMINE_CHANGES.backend.outputs['hasChanges.result'] ]
    jobs:
      - job: PrintVariables
        steps:
          - bash: |
              echo "Backend changes detected: $(backend_changes)"
            name: debugStep

So even though we're seemingly reading the same variable in the same place, the syntax is different. What fun.

Thoughts, comments? Send me an email!

#azure #tech