在Azure DevOps管道中的各个阶段共享变量 [英] Share variables across stages in Azure DevOps Pipelines

查看:289
本文介绍了在Azure DevOps管道中的各个阶段共享变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图弄清楚如何在脚本中跨ADO管道共享自定义变量.下面是我的脚本,分为两个阶段.

I am trying to figure out how to share custom variables across ADO pipelines in my script. Below is my script with 2 stages.

我将curProjVersion设置为输出变量,并尝试从另一个阶段访问它.我做对了吗?

I am setting the curProjVersion as an output variable and trying to access it from a different stage. Am I doing it right?

stages:
- stage: Build
  displayName: Build stage
  jobs:
  - job: VersionCheck
    pool:
      vmImage: 'ubuntu-latest'
    displayName: Version Check
    continueOnError: false
    steps:

      - script: |
          echo "##vso[task.setvariable variable=curProjVersion;isOutput=true]1.4.5"
        name: setCurProjVersion
        displayName: "Collect Application Version ID"

- stage: Deploy
  displayName: Deploy stage
  dependsOn: Build
  variables:
    curProjVersion1: $[ dependencies.Build.VersionCheck.outputs['setCurProjVersion.curProjVersion'] ]
  jobs:
  - job: 
    steps: 
      - script: |
          echo $(curProjVersion1)

推荐答案

在Azure DevOps管道中的各个阶段共享变量

Share variables across stages in Azure DevOps Pipelines

恐怕要说的是,它不支持共享在一个阶段中定义的变量并将其传递到另一阶段.

I'm afraid to say that it does not supported to share the variable which defined in one stage and pass it into another stage.

这是我们计划添加的功能,但到目前为止,尚不支持.您可以按照 Github问题进行操作,许多人与您有相同的需求.您可以跟踪它.

This is the feature we are plan to add, but until now, it does not supported. You can follow this Github issue, many people has the same demand with you. You can follow track that.

直到现在,我们仅支持设置

Until now, we only support set a multi-job output variable, but this only support YAML. For Classic Editor, there's no any plan to add this feature in release.

要解决此问题,您可以在阶段之前预定义变量.但重要的是,如果您要一步改变它的价值.新值无法传递到下一个阶段.具有新值的变量的生存期仅存在于阶段中.

For work around, you can predefined the variables before the stages. But one important thing is if you change its value in one stage. The new value could not be passed to the next stage. The lifetime of variable with new value only exists in stage.

已更新:

跨阶段共享变量功能已在

Share variables across stages feature has been released in Sprint 168 now.

请使用以下格式访问上一阶段的输出变量:

Please use below format to access output variables from previous stage:

stageDependencies.{stageName}.{jobName}.outputs['{stepName}.{variableName}'] 

这篇关于在Azure DevOps管道中的各个阶段共享变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆