Was previously using TFS2013 and XAML-based builds. Had created a number of custom tasks for the XAML builds in C#, including one to set the build number programmatically through the TFS .NET Client API libraries (not the REST API). Have now moved
to TFS2015 and trying to move to vNext-based builds. Trying to convert our C#-based customizations to the new build process by re-coding as PowerShell scripts. I am trying to use the following script to programmatically set the build number (as
we did previously via C#):
#STEP1: load the TFS assemblies
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Client")
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Build.Common")
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Build.Client")
#STEP2: get the collection
$collection=[Microsoft.TeamFoundation.Client.TfsTeamProjectCollectionFactory]::GetTeamProjectCollection($env:SYSTEM_TEAMFOUNDATIONCOLLECTIONURI)
#STEP3: get the build server
$buildServer=$collection.GetService([Microsoft.TeamFoundation.Build.Client.IBuildServer])
#STEP4: get the details for the currently running build
$buildDetail = $buildServer.GetBuild($env:BUILD_BUILDURI)
#STEP5: update the build number
$buildDetail.BuildNumber = "1.2.3.4-MyBuild"
#STEP6: save the changes to the build details
$buildDetail.Save()
Everything seems to work just fine until "STEP6" when I try and save the change made to the "BuildNumber". When the "Save()" method is called, the following error is generated:
Exception calling "Save" with "0" argument(s): "TF215070: The build URI vstfs:///Build/Build/40177 is not valid. Make sure that this build exists and has not been deleted.
As best I can tell, STEP #4 is returning an instance that implements the "Microsoft.TeamFoundation.Build.Client.IBuildDetail" interface (as I expected it would). Also, clearly the build URI is valid as it is specifically used to load
the build information in that same step. Again, this logic mimics the same logic we use in our C#-based XAML customizations, just re-written under PowerShell.
Searching the internet, I can find nothing related to this error and cannot figure out why I would be receiving it. I did find a (much more complex) version of what I am trying to do here:
https://github.com/voice4net/build-scripts/blob/master/ApplyVersionFromSourceControl.ps1. While I haven't tried using this script directly, it appears to be doing basically the same thing and, presumably, worked for its author.
Is there anyone out there that can help me understand this error, why I am getting it, and--ideally--how to fix it?!
Thanks in advanced.