DevOpsInterviewPrep logo
← 🚀 Delivery & GitOps
Foundational

Azure Pipelines expression timing and output variables: follow when a value exists

Trace parameters and variables through Azure Pipelines evaluation phases. Pass a named step output between jobs without asking template expansion to read future runtime data.

TL;DR: Template expressions are evaluated while Azure constructs the pipeline plan. Runtime outputs arrive later. Map a named producer's output through the dependency context, then use it at a stage where it exists; changing expression punctuation cannot make a future value available earlier.

Start with the evaluation phase

${{ ... }} evaluates template expressions during plan construction. $[ ... ] evaluates runtime expressions in supported locations, while $(name) substitutes a macro variable before a task runs. Their available contexts differ. Parameters support typed configuration during expansion; ordinary variables are strings.

The Azure expressions reference describes these contexts. A job that discovers an artifact ID cannot retroactively use that ID to decide which template nodes were inserted before the job started.

rendering diagram…

Map a small output between jobs

This Azure Pipelines fixture uses a hosted Ubuntu agent and no external service. It illustrates same-stage jobs; cross-stage dependency syntax differs and must be chosen for that context.

trigger: none
pool:
  vmImage: ubuntu-latest
jobs:
  - job: Prepare
    steps:
      - bash: echo '##vso[task.setvariable variable=candidate;isOutput=true]fixture-17'
        name: identify
  - job: Inspect
    dependsOn: Prepare
    variables:
      candidate: $[ dependencies.Prepare.outputs['identify.candidate'] ]
    steps:
      - bash: test "$CANDIDATE" = 'fixture-17'
        env:
          CANDIDATE: $(candidate)

The producer step name, variable name and isOutput=true form the output contract. The consumer declares the dependency and maps the value at runtime. Validate this in an authorized Azure project; a YAML parser cannot emulate the service's variable engine.

For a negative case, rename identify without updating the dependency expression. The consumer's comparison must fail instead of accepting a missing identifier. Restore the reference and change the expected value to demonstrate that an incorrect candidate also fails. The quoted environment variable carries data into the shell without embedding an expression's raw value directly in shell source.

ValueEarliest useful pointExample use
Typed parameterTemplate expansionChoose a reviewed build variant
Static variablePlan construction where supportedSet known configuration
Named job outputAfter producer completesSelect the produced artifact
Task-set variableLater supported consumerPass a discovered nonsecret value

Absence must not become a release default

If the producer fails or is excluded, its output may be unavailable. Diagnose that outcome before the expression itself. A missing digest must block a deployment, not select a mutable tag. Preserve a known producer-to-candidate relationship and verify the value before contacting a target.

For cross-stage handoff, Azure uses dependency contexts appropriate to where the expression is evaluated, including stageDependencies for mapping stage outputs into jobs. Avoid mechanically adding one more dotted name to a same-stage example. Consult the reference for the specific stage/job/deployment-job form.

Self-check: a compile-time if reads a value set by a previous runtime job. Can Azure insert the requested stage afterward? No. Construct the planned graph from available inputs and use a runtime condition for the already-planned stage, or design a separate pipeline invocation with an explicit input contract.

Practice a missing Azure output, then review conditions and dependency status.

RELATED CONCEPTS
PRACTICE THIS IN REAL QUESTIONS