Reputation: 10088
I have an Azure Devops build YAML file that contains the following task:
- task: PowerShell@2
displayName: 'Set coverage variable'
inputs:
targetType: 'inline'
script: Write-Host "##vso[task.setvariable variable=coverage]Get-Content .\coverage\lcov-report\summary.txt"
I would like this task to set the variable coverage
to be the value of the contents of summary.txt
. However, when accessing the variable in the following task, I see that the variable is literally the string Get-Content .\coverage\lcov-report\summary.txt
.
There seems to be no example anywhere in the documentation as to how to pull this off. Is it just a limitation of scripting? Do I have to set the Get-Content
command to a variable and then access that variable?
Upvotes: 2
Views: 3120
Reputation: 51183
Actually, it's documented. But may be not too obvious in our official doc :) You could find related doc here:
Important
Predefined variables that contain file paths are translated to the appropriate styling (Windows style C:\foo\ versus Unix style /foo/) based on agent host type and shell type. If you are running bash script tasks on Windows, you should use the environment variable method for accessing these variables rather than the pipeline variable method to ensure you have the correct file path styling.
Since you are using is pipeline variable, the value returned by 'Get-Content .\coverage\lcov-report\summary.txt'
as a string type, it's an expected behavior.
However $() accepts a variable not a string. Use $(Get-Content .\coverage\lcov-report\summary.txt)
After this, in the following task, simple use below to read the value.
Write-Host No problem reading $env:coverage
Upvotes: 1
Reputation: 1743
Please use $() after ].
Example:
##vso[task.setvariable variable=coverage]$(Get-Content .\coverage\lcov-report\summary.txt)"
Upvotes: 5