简体   繁体   English

azure devops 管道中带有变量的 displayName

[英]displayName with variable in azure devops pipeline

I have build a yaml pipeline which has multiple stages in them.我已经构建了一个 yaml 管道,其中有多个阶段。 To ensure all the stages are using the same git tag, I am trying to display the git tag in the displayName of each stage.为了确保所有阶段都使用相同的 git 标签,我试图在每个阶段的 displayName 中显示 git 标签。

I have a job within the stage which goes and finds the git tag我在舞台上有一份工作,找到 git 标签

stages:
  - stage : stageA
    jobs:
        - job: Tag
          steps:
            - bash: |
                tag=`git describe --tags --abbrev=0` && echo "##vso[task.setvariable variable=version_tag;isOutput=true]$tag"
                echo "$tag"
              name: setTag

How can I use the $tag under displayName in the next stage of the pipeline?如何在管道的下一阶段使用 displayName 下的 $tag?

How can I use the $tag under displayName in the next stage of the pipeline?如何在管道的下一阶段使用 displayName 下的 $tag?

No, runtime variables are absolutely impossible to get in compile time.不,运行时变量绝对不可能在编译时获得。 The values of display name are captured before any of the stage actually run, unless you pass a compile-time expression, otherwise anything will be handled as 'string'.显示名称的值在任何阶段实际运行之前被捕获,除非您传递编译时表达式,否则任何内容都将作为“字符串”处理。

Take a look of this:看看这个:

https://learn.microsoft.com/en-us/azure/devops/pipelines/process/variables?view=azure-devops&tabs=yaml%2Cbatch#understand-variable-syntax https://learn.microsoft.com/en-us/azure/devops/pipelines/process/variables?view=azure-devops&tabs=yaml%2Cbatch#understand-variable-syntax

Only this situation can work:只有这种情况可以工作:

trigger:
- none

pool:
  vmImage: ubuntu-latest

stages:
- stage: A
  jobs:
  - job: A1
    steps:
     - bash: |
          tag="testtag"
          echo "##vso[task.setvariable variable=myStageVal;isOutput=true]$tag"
       name: MyOutputVar
- stage: B
  dependsOn: A
  jobs:
  - job: B1
    variables:
      myStageAVar: $[stageDependencies.A.A1.outputs['MyOutputVar.myStageVal']]
    steps:
      - bash: echo $(myStageAVar)

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM