views:

409

answers:

2

We have a central Team Foundation Server (2008) deployment where all projects get stored. Each project sets up their own build server running Team Build to do their own automated builds.

Here's the problem. When a connection error is detected between TFS and the Team Build server, it moves the build agent's status to 'unreachable' which means it's not available for any subsequent builds. Our servers have scheduled reboot windows and when TFS can't communicate with those agents (or vice-versa) during that window, it moves the agent to 'unreachable'. Every morning we come in and find that we have to manually go in and reenable the agent.

Is it possible to have the team build agents come back online as soon they're available again? Or perhaps write a script that brings them back online automatically?

+1  A: 

In TFS2008, the AT should ping the unreachable build agent on a regular period (15-30 minutes, can't remember the interval at the moment) to see if it is back up. Are you not seeing this behaviour - do yours stay unreachable?

That said, it is possible to write a bit of .NET code that you could run periodically to set the status of the build agent. Alternatively you could run it as a scheduled task after start-up on the windows machine that is running as your build agent to go talk to TFS and set it's status back to good.

To write the code, you want to use the TFS Build API (Microsoft.TeamFoundation.Build.Client). In particular you want to look at the IBuildAgent. Get the appropriate one from the IBuildServer, change the status and then call buildAgent.Save().

Martin Woodward
No, ours doesn't exhibit that behavior, it will just stay unreachable until somebody manually goes in and changes the status. That's excellent information though, I wasn't aware that capability existed in the TFS Build API -- that's what I'll do.
The Matt
+1  A: 

I've also seen that problem myself - Here's a Powershell script that will iterate all build agents on all Team Projects and enabled them. Note that the agents will be updated to enable immediately regardless of whether they are valid (so if the build server is still down when the script runs - as soon as a build triggers - it will revert to Unreachable)

$serverName = "TFSRTM08"
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Client")
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.WorkItemTracking.Client")
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Build.Client")
$tfs = [Microsoft.TeamFoundation.Client.TeamFoundationServerFactory]::GetServer($serverName)
$wit = $tfs.GetService("Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore")
$bld = $tfs.GetService("Microsoft.TeamFoundation.Build.Client.IBuildServer")

$prjs = $wit.Projects
foreach ($proj in $prjs)
{
    $agents = $bld.QueryBuildAgents($proj.Name)
    foreach ($agent in $agents)
    {
     if ($agent.Status -ne "Enabled")
     {
      Write-Output "Enabling Build Agent: " $agent.Name " on Team Project: " $proj.Name " status was " $agent.Status
      $agent.Status = "Enabled"
      $agent.Save()
     }
    }
}
fuzzbone