Azure Pipeline: Passing variable to multiple stages

is it possible to declare a variable and then pass it downstream? I have an image below StageA -> StageB -> StageC where I obtain a url for my storage account on StageA, and I want to use it for both Stage B and StageC

But if I use the [stagedependencies.StageA.JobA.outputs['var'], it only works on StageB and not on StageC

- stage: 'StageC'
  dependsOn: 'StageB'
  pool:
    vmImage: 'windows-latest'
  variables:
    blobUri: $[stageDependencies.StageA.JobA.outputs['createOutput.blobUri']]
  jobs:
  - job: 'JobC'
    steps:
    - checkout: none
    - download: none
    - powershell: |
        echo JobBUri: $(blobUri)    

enter image description here

Maybe I missed it somewhere but does this mean you can only obtain the variable from the immediate stage you depend?

Example:

trigger:
- master

pool:
  vmImage: ubuntu-latest

stages:
- stage: 'StageA'
  jobs:
  - job: 'JobA'
    steps:
    - task: Powershell@2
      name: 'createOutput'
      inputs:
        targetType: 'inline'
        script: |
          Write-Output "##vso[task.setvariable variable=blobUri;isOutput=true]www.google.com"
- stage: 'StageB'
  dependsOn: 'StageA'
  pool:
    vmImage: 'windows-latest'
  variables:
    blobUri: $[stageDependencies.StageA.JobA.outputs['createOutput.blobUri']]
  jobs:
  - job: 'JobB'
    steps:
    - powershell: |
        echo JobBUri: $(blobUri)    

- stage: 'StageC'
  dependsOn: 'StageB'
  pool:
    vmImage: 'windows-latest'
  variables:
    blobUri: $[stageDependencies.StageA.JobA.outputs['createOutput.blobUri']]
  jobs:
  - job: 'JobC'
    steps:
    - powershell: |
        echo JobBUri: $(blobUri)    


Read more here: https://stackoverflow.com/questions/66278125/azure-pipeline-passing-variable-to-multiple-stages

Content Attribution

This content was originally published by Magikarp at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: