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 ??
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)'

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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With