RazorSPoint
RazorSPoint

Azure DevOps Sprint Update: Cross Staging Variables supported natively

Sebastian SchützeSebastian Schütze

Great news! Rob Ros and I posted about on how to solve the problem of having variables across stages:

Robs blog post

https://rajbos.github.io/blog/2020/04/17/Azure-DevOps-update-release-variable-across-stages

And mine

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.

Sebastian is an Azure Nerd with focus on DevOps and Azure DevOps (formerly VSTS) that converted from the big world of SharePoint and O365. He was working with O365 since 2013 and loved it ever since. As his focus shifted in 2017 to more DevOps related topics in the Microsoft Stack. He learned to love the possibilities of automation. Besides writing articles in his blog and German magazines, he is still contributing to the SharePoint Developer Community (and PnP SharePoint) to help to make the ALM part a smoother place to live in.

Comments 3
  • Matt Cooper
    Posted on

    Matt Cooper Matt Cooper

    Reply Author

    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”


This site uses Akismet to reduce spam. Learn how your comment data is processed.