azure-devopsmultistage-pipeline

Pass output variable to different stages


I have a pipeline in Azure DevOps that essentially look like this

stage: BuildStage
   job: SetUp
   job: Compile
stage: DeployStage
   job: Deploy

In the SetUp job I define an output variable, which I can define in the Compile job using e.g.

variables:
   MyVariableFromSetUp: $[ dependencies.SetUp.outputs['MyVariable'] ]

The question is, how can I do the same in the Deploy job? I don't want to run the SetUp stage twice as it is time consuming to calculate the value of MyVariable hence I must cache it.

The DeployStage has a dependsOn to BuildStage, but it appears I cannot use the dependencies as I expected. The documentation fails to mention the multi-stage case when dealing with variables.


Solution

  • Hey there is no direct way to do this at present based on what I have found, you would be following one of the following 3 methods

    1. Passing it as artifact value using this method https://medium.com/microsoftazure/how-to-pass-variables-in-azure-pipelines-yaml-tasks-5c81c5d31763

    2. Passing it via a API Endpoint using VSTeam powershell module https://www.donovanbrown.com/post/Passing-variables-from-stage-to-stage-in-Azure-DevOps-release, similar method can also be found here https://stefanstranger.github.io/2019/06/26/PassingVariablesfromStagetoStage/