Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

azure-pipelines - print variable to output

I am struggling with this simple task:

variables:
  myVariable: 'ValueFromVar'

- task: PowerShell@2
  inputs:
    targetType: 'inline'
    script: ${myVariable} # prints empty

- task: PowerShell@2
  displayName: Display version of app
  inputs:
    targetType: 'inline'
    script: 'Write-Host "Version of app: ${myVariable}"' # prints empty

- task: Bash@3
  inputs:
    targetType: 'inline'
    script: echo '${myVariable}' # prints ${myVariable} 

What is the correct way how to print a variable to output within azure pipeline ??

like image 759
Alamakanambra Avatar asked Dec 03 '25 13:12

Alamakanambra


2 Answers

About how to use custom variables, please check the doc Set variables in pipeline.

In your case, when you want to use the variable, it should be $(myVariable) instead of ${myVariable}.

Please refer to below demo:

variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'
  myVariable: 'ValueFromVar'

steps:
- task: PowerShell@2
  inputs:
    targetType: 'inline'
    script: '"$(myVariable)"'

- task: PowerShell@2
  displayName: Display version of app
  inputs:
    targetType: 'inline'
    script: 'Write-Host "Version of app: $(myVariable)"' 

- task: Bash@3
  inputs:
    targetType: 'inline'
    script: echo '$(myVariable)'

enter image description here

like image 110
Yang Shen - MSFT Avatar answered Dec 06 '25 07:12

Yang Shen - MSFT


A clean one line approach is to use the CmdLine task shortcut:

- script: echo $(myVariable)

Add display name etc. if needed e.g.

- script: echo $(myVariable)
  displayname: My variable value
like image 34
noontz Avatar answered Dec 06 '25 08:12

noontz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!