Mariusz, Gorzoch tech Blog

How to enumerate all active builds in TFS 2012

leave a comment »

During migration of TFS 2012 we found that we have couple of inactive build controllers with we can not delete because there are pending builds on theirs queues. Unfortunately the problem was that you can not just simply use some magic option in build menu to find out what are those builds. In order to get that information you need to go project by project and see what builds are pending.  Lucky there is easier way with a little bit of code :). Before you start you need to install “Visual Studio 2012 SDK” (http://visualstudiogallery.msdn.microsoft.com/b2fa5b3b-25eb-4a2f-80fd-59224778ea98?SRC=VSIDE) with you can find thru Visual Studio extension manager.

Once you do above then create new console project and add references to

  • Microsoft.TeamFundation.Client
  • Microsoft.TeamFundation.Common
  • Microsoft.TeamFundation.Build.Client
  • Microsoft.TeamFundation.Build.Common

and past into your main function below code:

            TfsTeamProjectCollection teamProjectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("http://{tfsServer}:8080/tfs/{ProjectCollection}"));
            var buildServer = teamProjectCollection.GetService<IBuildServer>();

            foreach (IBuildController controller in buildServer.QueryBuildControllers(true))
                Console.WriteLine("{0}:{1}",controller.Name, controller.QueueCount);
                var qspec = buildServer.CreateBuildQueueSpec("*", "*");
                var res = buildServer.QueryQueuedBuilds(qspec);

                foreach (var qb in res.QueuedBuilds)


Now just replace :

  • {tfsServer} with your tfs server name
  • {projectCollection} with you project collection

and you are done. Once you run above then you should get list of all active builds


Written by Mariusz Gorzoch

17 July 2013 at 09:04

Posted in Bez kategorii

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: