Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7019535
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:11:46+00:00 2026-05-27T23:11:46+00:00

Apologies, this is almost certainly a duplicate of this question but as that one

  • 0

Apologies, this is almost certainly a duplicate of this question but as that one hasn’t been answered I’m going to try again.

I’m trying to build a tool which will allow me to see all of the builds either Queued or Running on TFS.

One of the requirements is to be able to see which build server a build is running on. All of the “BuildAgent” properties and methods in the IQueuedBuildsView are deprecated and throw not implemented exceptions. There are lots of ways of querying an agent but you need the agent uri or name before you can do that and I feel like I’m in a chicken and egg situation.

Does anyone know how to find the build server name for a running build? My code snippet below might help.

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Net;
using System.Text;
using Microsoft.TeamFoundation.Server;
using Microsoft.TeamFoundation.Build.Client;
using Microsoft.TeamFoundation.VersionControl.Client;
using Microsoft.TeamFoundation.Framework.Client;
using Microsoft.TeamFoundation.Framework.Common;
using Microsoft.TeamFoundation.Client;


namespace TeamFoundationServerTools
{
    public static class TeamBuildData
    {

        public static void Main()
        {

            Uri teamFoundationServerUri = new Uri("http://tfs:8080/tfs");
            Uri teamFoudationServerProjectCollectionUri = new Uri("http://tfs:8080/tfs/collection");
            string teamFoundationServerName = "tfs";
            string teamFoundationServerProjectCollectionName = string.Empty;
            string teamFoundationServerProjectName = string.Empty;

            try
            {

                Dictionary<string, Uri> collections = new Dictionary<string, Uri>();

                if (string.IsNullOrEmpty(teamFoundationServerProjectCollectionName))
                {
                    DetermineCollections(teamFoundationServerUri, collections);
                }
                else
                {
                    collections.Add(teamFoundationServerName, teamFoudationServerProjectCollectionUri);
                }

                QueryCollections(teamFoundationServerName, teamFoundationServerProjectName, collections);

            }
            catch (Exception ex)
            {
                Console.Write(ex.ToString());
            }
        }

        /// <summary>
        /// Queries the Team project collection for team builds
        /// </summary>
        /// <param name="teamFoundationServerName">the name of the TFS server</param>
        /// <param name="teamFoundationServerProjectName">the name of the Team Project</param>
        /// <param name="collections">the Team Project Collections to be queried</param>
        private static void QueryCollections(string teamFoundationServerName, string teamFoundationServerProjectName, Dictionary<string, Uri> collections)
        {
            foreach (KeyValuePair<string, Uri> collection in collections)
            {
                // connect to the collection
                using (TfsTeamProjectCollection teamProjectCollection = new TfsTeamProjectCollection(collection.Value, CredentialCache.DefaultCredentials))
                {
                    Console.WriteLine(teamProjectCollection.Name);

                    IBuildServer buildServer = (IBuildServer)teamProjectCollection.GetService(typeof(IBuildServer));

                    // get ICommonStructureService (later to be used to list all team projects)
                    ICommonStructureService commonStructureService = (ICommonStructureService)teamProjectCollection.GetService(typeof(ICommonStructureService));

                    // I need to list all the TFS Team Projects that exist on a server
                    ProjectInfo[] allTeamProjects;

                    if (!String.IsNullOrEmpty(teamFoundationServerProjectName))
                    {
                        allTeamProjects = new ProjectInfo[1];
                        allTeamProjects[0] = new ProjectInfo();
                        allTeamProjects[0] = commonStructureService.GetProjectFromName(teamFoundationServerProjectName);
                    }
                    else
                    {
                        allTeamProjects = commonStructureService.ListProjects();
                    }

                    // iterate thru the team project list
                    foreach (ProjectInfo teamProjectInfo in allTeamProjects)
                    {
                        Console.WriteLine(teamProjectInfo.Name);

                        // skip this team project if it is not WellFormed.
                        if (teamProjectInfo.Status != ProjectState.WellFormed)
                        {
                            continue;
                        }

                        IQueuedBuildsView queuedBuildsView = buildServer.CreateQueuedBuildsView(teamProjectInfo.Name);
                        queuedBuildsView.StatusFilter = QueueStatus.Queued | QueueStatus.InProgress | QueueStatus.Postponed;

                        queuedBuildsView.QueryOptions = QueryOptions.All;

                        queuedBuildsView.Refresh(false);
                        foreach (IQueuedBuild queuedBuild in queuedBuildsView.QueuedBuilds)
                        {
                            Console.WriteLine(queuedBuild.BuildDefinition.Name);
                            Console.WriteLine(queuedBuild.BuildController.Name);
                            Console.WriteLine(queuedBuild);
                            Console.WriteLine(queuedBuild.Status);
                            Console.WriteLine(queuedBuild.RequestedBy);
                            Console.WriteLine(queuedBuild.QueuePosition);
                            Console.WriteLine(queuedBuild.QueueTime);
                            Console.WriteLine(queuedBuild.Priority);
                            Console.WriteLine();

                            if (queuedBuild.Status == QueueStatus.InProgress)
                            {


                            }

                            Console.WriteLine("***********************");

                        }
                    }
                }
            }

            Console.ReadLine();
        }

        /// <summary>
        /// Determins the team project collections for a given TFS instance
        /// </summary>
        /// <param name="teamFoundationServerUri">the uri of the Team Foundation Server</param>
        /// <param name="collections">a dictionary of collections to be added to</param>
        private static void DetermineCollections(Uri teamFoundationServerUri, Dictionary<string, Uri> collections)
        {
            // get a list of Team Project Collections and their URI's
            using (TfsConfigurationServer tfsConfigurationServer = new TfsConfigurationServer(teamFoundationServerUri))
            {
                CatalogNode configurationServerNode = tfsConfigurationServer.CatalogNode;

                // Query the children of the configuration server node for all of the team project collection nodes
                ReadOnlyCollection<CatalogNode> tpcNodes = configurationServerNode.QueryChildren(
                        new Guid[] { CatalogResourceTypes.ProjectCollection },
                        false,
                        CatalogQueryOptions.None);

                foreach (CatalogNode tpcNode in tpcNodes)
                {
                    ServiceDefinition tpcServiceDefinition = tpcNode.Resource.ServiceReferences["Location"];

                    ILocationService configLocationService = tfsConfigurationServer.GetService<ILocationService>();
                    Uri tpcUri = new Uri(configLocationService.LocationForCurrentConnection(tpcServiceDefinition));

                    collections.Add(tpcNode.Resource.DisplayName, tpcUri);
                }
            }
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T23:11:47+00:00Added an answer on May 27, 2026 at 11:11 pm

    I created a LinqPad script to do this. By querying all the Agents on a Controller you can see the builds running against each one. There’s some extra stuff in the script that I have added for my own preference.

    TFS Build Agents on my SkyDrive

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This has almost certainly been asked here before, so apologies if it's a duplicate.
Apologies if this has been answered already but I have yet been unable to
Apologies if this has already been answered many times, but I was unable to
Apologies if this is too ignorant a question or has been asked before. A
Apologies if this question is a bit obscure, I've been banging my head against
Apologies if this is a dumb question. In previous ASP.NET projects, I've been using
Apologies if this is a slightly noob question, but looking to clarify my thoughts
Apologies if this has been answered previously. Say I have the following table: colA
Apologies if this is classic ASP 101, but its been so long since I
Apologies if this has been answered before (I couldn't find the answer when I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.