Naeem Sarfraz

Blogging about Enterprise Architecture, ALM, DevOps & happy times coding in .Net

Trigger an Agent Release from TFS 2013 Build

You’re using TFS 2013 to build your application continuously, or on a schedule or both giving you feedback on how good your team are doing at integrating their work with one another. Using Release Management (RM) you can deploy your application into your Dev environment, then UAT and finally Production all at the click of a button. This post describes how you can trigger that build from a TFS 2013 build.

How could you use this and why? A product team wants to deploy to a Dev environment on every commit to the central repository. This environment is used by the developers to test the integration of all of the different components of a product before releasing into UAT. This can be described as Continuous Deployment. If the product has many components to it you may not want to deploy on every commit instead you could deploy daily as a result of a scheduled build e.g. a nightly build.

You can do this by triggering a release from a TFS build by modifying the build process template, used by your build definition, of which there are several:

  • DefaultTemplate.xaml
  • GitTemplate.xaml
  • TfvcTemplate.xaml
  • UpgradeTemplate.xaml

Installing the new build process template

Install RM and new versions of the above templates are installed on your server for you to use. On the server where you have installed RM Server go to C:\Program Files (x86)\ Microsoft Visual Studio 12.0\ReleaseManagement\bin\ where you’ll find the following files:

  • ReleaseDefaultTemplate.xaml – TFS 2010
  • ReleaseDefaultTemplate.11.1.xaml – TFS 2012
  • ReleaseGitTemplate.12.xaml – TFS 2013
  • ReleaseTfvcTemplate.12.xaml – TFS 2013
  • ReleaseUpgradeTemplate.xaml – TFS 2010

You can also find these files on a machine where you have installed the RM client application, the location is C:\Program Files (x86)\Microsoft Visual Studio 12.0\Release Management\Client\bin (just be aware that some have reported the templates in the RM Client directory might not work). The RM client can be downloaded from your MSDN subscription or from here which is a limited trial version. Now add these files to source control by creating a folder called BuildProcessTemplates at the root of your Team Project repository and drop these files into there and commit (or checkin) so the path looks something like (for TFSVS) $/MyTeamProject/BuildProcessTemplates/ReleaseTfvcTemplate.12.xaml.

Capture

Configure your build

Create your new build and select one of the new templates:

image

You’ll want to take note of the following RM-specific properties:

image

  • Configuration to Release – String array, normally set to Any CPU|Release
  • Release Build – Boolean value (true or false), true if you want to trigger the release
  • Release Target Stage – String value, if you set this to the name of one of your RM stages e.g. DEV, PROD if you want to deploy into that enviornment only otheriwse leave blank

The new release process templates trigger RM by making a call to ReleaseManagementBuild.exe, which you’ll get when you install the RM client. This means wherever you have a TFS Build agent installed you will need to have the RM client also installed on that machine.

Trigger a new build and confirm that your release was created and then triggered ReleaseManagementBuild.exe. Using the RM client you should see a new release created.

Modifying an existing build process template

You may have modified one of the default templates or created your own version of it in which case you will want to add the RM capabilities to it. There is a post over at MSDN on the Visual Studio ALM blog that details exactly how to do this.

blog comments powered by Disqus