How to queue a new build using TFS API

Another post on TFS API, my last post was related to how to get build Definitions and Build Details from TFS 2010, and this post is about how to queue a new build in TFS 2010 Server.

As earlier you need to add reference of following assemblies

  1. Microsoft.TeamFoundation.dll
  2. Microsoft.TeamFoundation.Client.dll
  3. Microsoft.TeamFoundation.Build.Client.dll

which will be available under – C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ReferenceAssemblies\v2.0\ location.

And here is the code snippet

var tfsName = "http://dotnetthoughts:8080/tfs/defaultcollection";
var tfs = new TeamFoundationServer(tfsName, new UICredentialsProvider());
tfs.EnsureAuthenticated();
if (tfs.HasAuthenticated)
{
	var buildServer = tfs.GetService(typeof(IBuildServer)) as IBuildServer;
	var buildDefinition = buildServer.GetBuildDefinition("", "");
	buildServer.QueueBuild(buildDefinition);
}
catch (Exception exception)
{
    MessageBox.Show(exception.Message);
    throw;
}

Here is how it works, we are connecting and getting the TFS Server, then getting the Build Server using GetService method. And to get the build definition instead of the earlier post(to get all the Build definitions, we are passing “*”), we need to specify the Team project and Build name(Build definitions are unique per team project in TFS). Then we can call QueueBuild() method on Build server object, with build definition as the parameter, which will queue the build definition default values.

Happy coding :)

This entry was posted in .Net, .Net 4.0, Version Control and tagged , , , , , . Bookmark the permalink.

One Response to How to queue a new build using TFS API

  1. Pingback: How to queue a new build using TFS API | .NET | Syngu

Leave a Reply

Your email address will not be published. Required fields are marked *

*


*

You may use these HTML tags and attributes: <a href="" title="" rel=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>