Great news! Rob Ros and I posted about on how to solve the problem of having variables across stages:
Robs blog post
Robs approach is for classic pipelines and mine was for YAML pipelines which was inspired by a PR from . But it was not very natively possible.
But now with the new Sprint update 168 from May 4th 2020 it is possible. Now the question: How do you create an output variable in a YAML pipeline? It is fairly easy!
powershell: "Write-Host '##vso[task.setvariable variable=foo;isOutput=true]bar'"
You basically use PowerShell to persist a new variable. And according to their documentation, it should work like the following.
trigger: - master resources: - repo: self pool: vmImage: 'ubuntu-16.04' variables: MyVar: 'MyVal' stages: - stage: Save_Variable jobs: - job: Save_Variable steps: - pwsh: Write-Host "##vso[task.setvariable variable=MyVar;isOutput=true]NewVal" name: MyOutputVar - stage: Read_Variables dependsOn: Save_Variable jobs: - job: Read_Variable variables: prevStageVar: $[stageDependencies.Save_Variable.Save_Variable.outputs['MyOutputVar.MyVar']] steps: - powershell: 'Write-Host "Get Stage variable: $(prevStageVar)"'
I am not 100% sure since the rollout still has to happen, but it is very similar as you would do it cross-job in the same stage.
Also published on Medium.
Hi there, I’m the Azure Pipelines product manager responsible for this area. Thanks for the blog post!
I think you have an error in your sample code. In the Save_Variable job, when you create the variable, you should have an “isOutput=true” in the ##vso command. Like this:
Write-Host “##vso[task.setvariable variable=MyVar;isOutput=true;]NewVal”
Thanks Matt. I will be correcting this!