displayName with variable in azure devops pipeline

Viewed 34

I have build a yaml pipeline which has multiple stages in them. 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.

I have a job within the stage which goes and finds the git tag

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?

1 Answers

How can I use the $tag under displayName in the next stage of the pipeline?

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

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)

enter image description here

Related