1

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
pianomanjh
  • 233
  • 1
  • 14
  • Hers is a example "Use a script to customize your build process", you can have a check: https://msdn.microsoft.com/Library/vs/alm/Build/scripts/index – Cece Dong - MSFT Oct 28 '15 at 07:43
  • Thanks for this, unfortunately, this doesn't assign to a custom build variable for later use. It just reads from a predefined variable and adjusts a file. – pianomanjh Oct 28 '15 at 15:41

1 Answers1

2

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.

Phiter
  • 14,570
  • 14
  • 50
  • 84
Kevin Kraus
  • 283
  • 1
  • 2
  • 11