OK - I've read all about environment variables and how they can't be set and read by the same process (even this can't be read by a later step in the build):
Environment.SetEnvironmentVariable("Major_Build_Number", BaseReleaseNumber, EnvironmentVariableTarget.Machine)
So has anyone come up with a simple way to pass along info from one build step to another? In my first step I determine the build number (this is a fairly complex process believe it or not) and I need to pass that build number to the last build step (which is a Copy Files step) so that it can copy the build into a folder that's named with the build number. I've tried setting an environment variable, but unfortunately that can't be set and read from the same session. There's gotta be a simple way to do this. Yes I could write a PS or batch script to do it and store the value in a file or the registry, but I would prefer to use the Copy Files task and I can't figure out how to pass that value along.
I tried defining a variable in the build definition and storing the value there but I can't seem to change that value after it's set in the build definition.
BTW, this is an on-premises installation - not VSTS.
Anyone have any ideas?
Thanks Andy for your response. So I tried this in SetBuildNumberENVVar.ps1
param([Int32]$MajorBuildNumber=0,[Int32]$MinorBuildNumber=0)
Write-Host "##vso[task.setvariable variable=MajorBuildNumber]$MajorBuildNumber"
Write-Host "##vso[task.setvariable variable=MinorBuildNumber]$MinorBuildNumber"
I then run it from the command line:
c:\powershell .\SetBuildNumberENVVar.ps1 23 45
and then try to echo the variable:
echo %MajorBuildNumber%
%MajorBuildNumber%
and as you can see it doesn't appear to work. I tried this from a C# script:
int.TryParse("$(MajorBuildNumber)", out mbn);
and mbn = 0 after this runs.
Any idea what I'm doing wrong?