is there a way to get tfs teambuild's controller (and agent) status from the command line?

StackOverflow https://stackoverflow.com/questions/9360195

  •  28-10-2019
  •  | 
  •  

Question

is there a way to get tfs 2010 teambuild's controller (and agent) status from the command line? my controllers (have got about 20) keep on having to be restarted (we know why this is) and I'd like a way to run a script (psexec?) to check what's stayed up. Cheers

Was it helpful?

Solution

It's possible to have a small console app that does this for you as follows:

using System;
using Microsoft.TeamFoundation.Build.Client;
using Microsoft.TeamFoundation.Client;

namespace GetAgentsStatus
{
    class Program
    {
        static void Main()
        {
            TfsTeamProjectCollection teamProjectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("CollectionUri"));
            IBuildServer buildService = (IBuildServer)teamProjectCollection.GetService(typeof(IBuildServer));
            IBuildController buildController = buildService.GetBuildController("BuildControllerName");

            foreach (var agent in buildController.Agents)
            {
                if(agent.Status == AgentStatus.Offline || agent.Status == AgentStatus.Unavailable)
                {
                   Console.WriteLine(string.Format("{0} needs restarting",agent.Name));
                }
            }
        }
    }
}

If you open any build definition for editing, navigate to "Build Defaults" to retrieve the value of BuildControllerName

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top