问题
I have a Powershell script that needs to set a custom build variable, such that it can be used in a later task. I have successfully added a variable, and verified it can be accessed and set from Powershell, but, for whatever reason, the change does not persist when referencing the variable in a later build step.
Write-Host $env:VERSIONNUMBER #prints the variable value set in TFS Build
$env:VERSIONNUMBER = 'This doesn't stick'
Write-Host $env:VERSIONNUMBER #prints 'This doesn't stick', but not available after this task
回答1:
Try the following in your PowerShell script
Write-Host “##vso[task.setvariable variable=myvariable]newValue”
this worked for me in Release Management vNext, but I would assume it also works in the build system as well.
来源:https://stackoverflow.com/questions/33358708/tfs-build-vnext-how-to-write-to-a-custom-build-variable-from-powershell