7
- job: Display_Version
  displayName: Update version $(Number_Version) 
  steps: 
  ....

I am trying to display a variable which is the variables of the pipeline, and it does not display it ... Can anyone explain to me why?

  • Does this answer your question? [Azure pipeline set displayname of task based on condition](https://stackoverflow.com/questions/62896477/azure-pipeline-set-displayname-of-task-based-on-condition) – Matt Mar 31 '22 at 14:19
  • no because the variable is set manually before the run pipeline by dev –  Mar 31 '22 at 19:12
  • can you share with us, who you set value of the variable `$(Number_Version)`? – Somar Zein Apr 01 '22 at 09:58

1 Answers1

14

To use the pipeline-level variable in the displayName of a job or a stage, you should use the expression '${{ variables.varName }}'. Because the displayName of jobs and stages are set at compile time.

The expression '${{ variables.varName }}' is called template expression which can be used to get the value of variable at compile time, before runtime starts.

The macro syntax '$(varName)' can get the variable value during runtime before a task runs. So, you can use it in the displayName and the input of a task.

For more details, you can see this document.

Below is an example as reference.

  • azure-pipelines.yml

    variables:
      Number_Version: 1.1.0
    
    jobs:
    - job: Display_Version
      displayName: 'Job Name - Update version ${{ variables.Number_Version }}'
      pool:
        vmImage: ubuntu-latest
      steps:
      - task: Bash@3
        displayName: 'Task Name - Update version $(Number_Version)'
        inputs:
          targetType: inline
          script: echo "Input of task - Update version $(Number_Version)"
    
  • Result

    enter image description here

Bright Ran-MSFT
  • 5,190
  • 1
  • 5
  • 12