Trigger a vNext Release from team build

Using Release Management you can implement true Continuous Delivery.  With the latest update of Release Management you can trigger a release via a REST api call to Release Management.  In this post I will share the script and build definition I used to trigger the release and how to use them in your team build.

Although team build now allows us to run PowerShell scripts as part of our build we are still forced to create a custom build template.  The reason being the two opportunities provided by the default template are at the wrong points during the build.  We can run a PowerShell either before or after the build.  However, we need to run a PowerShell after the drop of the files. So the attached build template adds the ability to run a PowerShell after the files are copied to the drop location.

To use the ps1 and build template in your build they must be stored in TFS. So pick a location and check the files into TFS.  The files do not have to be stored together. We will use these server paths when we configure our build.

To create a new build definition using the build template attached just create a build like normal.  Once on the Process tab select the Show details button and click the New… button.  Use the Browse dialog to locate the new build template in TFS and click OK.  With the Trackyon.1.0.xaml selected you will have additional features most importantly for this post the “Post-drop script arguments” and “Post-drop script path”.  The value for “Post-drop script arguments” are Release Management Server name, Release Management Server Port, Team Project and Target Stage each separated by a space.  For example in the image below my Release Management Server name is “DemoDC” running on port 1000, my team project is “Scrum” and I want to target the “QA” stage of my release path.  The value for “Post-drop script path” is the server path to the trigger.ps1 file.


Now all you have to do is start your build to have it trigger a release in Release Management

Before I end this post I would like to touch on some challenges I faced with trying to use the REST api for Release Management.

One issue that was very difficult to troubleshoot was the requirement that the URL of TFS configured in Release Management on the Manage TFS tab must match exactly to the URL passed in by the script.  However, the value stored in $env:TF_BUILD_COLLECTIONURI used in the script is read from the Server URL in the Team Foundation Server Administration Console.  If those values do not match the release will fail.  You can use the Change URLs link in the Team Foundation Server Administration Console to change the Server URL so it matches the one in Release Management.

Just as a tip make sure you have Fiddler installed because the error messages from the REST api or not very informative.  I had to use Fiddler a couple of times to troubleshoot issues.

Trigger.ps1 (2.78 kb)

Trackyon.1.0.xaml (48.84 kb) (right click and Save Target As)

Comments are closed