Rishav Singh
Rishav Singh

Reputation: 343

How to see the Predefined Variables in Azure Devops

I want to see the values that is path of predefined variable like for $(System.DefaultWorkingDirectory) i want to see value stored in it. I am unable to find this variable value so where can i find it in Azure devops.

In simple words, how could i check what was the Build.SourcesDirectory or Build.Repository.LocalPath used in that particular release pipeline?

Upvotes: 14

Views: 18101

Answers (2)

djangofan
djangofan

Reputation: 29669

Simpler answer:

  - bash: |
      env | sort
    displayName: 'Debug: Show Env Vars'

Upvotes: -1

Krzysztof Madej
Krzysztof Madej

Reputation: 40603

I'm not sure if you find a specific place in Azure DevOps what values are behind. Values may differ a bit depending in which OS you select for your agent. However you can alwasy print them out. Please check doc here.

steps:
  - bash: echo $(System.DefaultWorkingDirectory)

To print all variables you can use this step (since variables are also available to scripts through environment variables)

 steps: # 'Steps' section is to be used inside 'job' section.
  - task: Bash@3
    inputs:
      targetType: 'inline'
      script: 'env | sort'

enter image description here

Another option which works for Windows and Linux would be (all credits to Joe):

- pwsh: (gci  env:* | sort-object name)

You can also use third party extension Print all variables

  - task: printAllVariables@1
    displayName: 'Print all variables via extension'

Or expression like:

  - ${{ each var in variables }}:
    - pwsh: Write-Host "${{ var.Key }} - ${{ var.Value }}"
      displayName: 'Print variables via expression in the loop'

Here is an example pipeline:

trigger: none
pr: none

name: Display pipeline variables

variables:
- group: DisplayPipelineVariables
- name: DB_HOSTNAME
  value: 10.123.56.222
- name: DB_PORTNUMBER
  value: 1521
- name: USERNAME
  value: TEST
- name: PASSWORD
  value: TEST
- name: SCHEMANAME
  value: SCHEMA  
- name: ACTIVEMQNAME
  value: 10.123.56.223
- name: ACTIVEMQPORT
  value: 8161

pool:
  vmImage: $(imageName)

jobs:
- job: AllEnvironmentVariables
  strategy:
    matrix:
      linux:
        imageName: 'ubuntu-latest'
      mac:
        imageName: 'macOS-latest'
      windows:
        imageName: 'windows-latest'
  steps:
  - script: env | sort
    displayName: Display all environment variables

- job: PipelineVariablesViaExtension
  strategy:
    matrix:
      linux:
        imageName: 'ubuntu-latest'
      mac:
        imageName: 'macOS-latest'
      windows:
        imageName: 'windows-latest'
  steps:
  - task: printAllVariables@1
    displayName: 'Print all variables via extension'

- job: PipelineVariablesViaExpression
  strategy:
    matrix:
      linux:
        imageName: 'ubuntu-latest'
      mac:
        imageName: 'macOS-latest'
      windows:
        imageName: 'windows-latest'
  steps:
  - pwsh: Write-Host "${{ convertToJson(variables) }}"
    displayName: 'Print all variables via expression'

- job: PipelineVariablesViaExpressionInLoop
  strategy:
    matrix:
      linux:
        imageName: 'ubuntu-latest'
      mac:
        imageName: 'macOS-latest'
      windows:
        imageName: 'windows-latest'
  steps:
  - ${{ each var in variables }}:
    - pwsh: Write-Host "${{ var.Key }} - ${{ var.Value }}"
      displayName: 'Print variables via expression in the loop'

Upvotes: 31

Related Questions