6

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?

Krzysztof Madej
  • 32,704
  • 10
  • 78
  • 107
Rishav Singh
  • 143
  • 1
  • 3
  • 14

2 Answers2

17

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'
Krzysztof Madej
  • 32,704
  • 10
  • 78
  • 107
  • No worries. All things above will work for you. I just mentioned this that value may differ depending OS. – Krzysztof Madej Apr 10 '20 at 08:46
  • This works on the cloud but not when I use my local machine as a build agent, even though I have bash installed on it (Windows 10). It just says, "'c:\WINDOWS\system32\bash.exe' failed with exit code 4294967295". Is there some sort of powershell equivalent of this? – Joe Feb 14 '21 at 20:03
  • 4
    Answering my own question in a comment: This powershell script works for both: `- pwsh: (gci env:* | sort-object name)` – Joe Feb 14 '21 at 20:12
-1

Simpler answer:

  - bash: |
      env | sort
    displayName: 'Debug: Show Env Vars'
djangofan
  • 28,471
  • 61
  • 196
  • 289