Monday, July 1, 2013

Add additional / multiple build controllers for Microsoft Team Foundation Server 2012

While Microsoft doesn't officially support a multi-controller scenario for Team Foundation Server (TFS), sometimes it is a necessity. Especially when you have multiple Team Project Collections and are left holding one build controller.

The following steps will allow you to build additional controllers and manage them, in TFS 2012. As always,  I recommend doing a snapshot or backup of your server prior to making high-level changes such as this.

  1. First, open a Command Prompt window (as an Administrator).
    • From the Windows 2012 Server screen right-click and go to All apps.
    • Under the Windows System category right-click on Command Prompt and select the option to Run as administrator.
  2. In the Administrator: Command Prompt window, type in the following command.

    Note: You need to replace the [service name] with your build controller's service name. Also, you need to replace the [display name] as well with something that makes sense for you. I've included some best practice examples for you. "BuildService-TeamProjectCollectionName" and for the Display Name you would enter "Visual Studio Team Foundation Build Service Host (TeamProjectCollectionName)" for example. Make sure to remove the placeholder brackets [ ] and to keep spacing as it is below. Or this will not work.

    sc.exe create [service name] binpath= "C:\Program Files\Microsoft Team Foundation Server 11.0\Tools\TFSBuildServiceHost.exe /NamedInstance:[service name]" DisplayName= "[display name]"

  3. Hit your Enter key. You should get a message that [SC] CreateService SUCCESS. Otherwise, review the command above to rule out any errors or mistakes in keying.
  4. Now you need to register the controller and agents via the Team Foundation Server Administration Console. However, if you open the console via your icon you will only see your original build controller.

    There is an easier way. Create a batch file (.BAT) on your desktop. Add the following code to it, modifying where appropriate and without the placeholder brackets [ ]:


    :: Set the service host environment variable
    set TFSBUILDSERVICEHOST.2012=[service name]

    :: Open the Team Foundation Server Administration Console
    "C:\Program Files\Microsoft Team Foundation Server 11.0\Tools\tfsmgmt.exe"

  5. Run the batch file. This should open a TFS Admin Console window where the new build controller is accessible.
  6. On the Build Configuration screen click on the Register link. This process is similar to that found here. Your registration properties should be left pretty much alone. The only exception here is the Display Name. Best practice is to call it your Default Controller - YourServiceName.
  7. In some cases there may be a conflict between your controller URI and the original controller (they both may try to use the same address / port). Give it a few minutes and if an error appears on the screen via logs do the following:
    1. Register a build controller + agent as explained here. Then unregister the build controller service.
    2. Re-register the build controller service. After which, modify the URL to use a different port.
    3. Register your build controller + agent as you normally would.
That's it. You should now have two or more build controllers that won't conflict with one another. And, you can use that batch (.BAT) to get back in to manage your build controller / agents as needed.

Good luck and I hope this helps.

2 comments:

  1. Hi, I'm trying to have multiple build controllers for TFS2013, I've managed to create the service but I can't open the console, I'think the env variable TFSBUILDSERVICEHOST.2012 has changed, do you know what is for TFS2013? tks

    ReplyDelete
  2. @facunda
    I don't personally have the Visual Studio 2013 Preview installed but I suspect if you look under your Windows Services for TFSBuildServiceHost you will find the correct service name. The path will always point to TFSBuildServiceHost as well. I would even wager a guess that it might be TFSBUILDSERVICEHOST.2013.

    ReplyDelete