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
- Microsoft.TeamFoundation.dll
- Microsoft.TeamFoundation.Client.dll
- 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


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