Inside TFS

Batched Gated Builds in Visual Studio 2012 TFS

Batched Gated Builds in Visual Studio 2012 TFS improves on the concept of gated builds by allowing you to specify a build definition to build more than one queued build at a time.

The past several columns have demonstrated the automated build process in Team Foundation Server, known as Team Foundation Build. This build service has been available in Team Foundation Server since the initial 2005 release, and has undergone some significant changes in the past seven years. This column introduces one of the new features available in the Visual Studio 2012 release: batched gated builds.

Gated builds have been available since Team Foundation Server 2010. Essentially, a gated build requires that, in order for a developer to check-in their code, the code must run through the build process successfully.

When a developer checks in their code, it's not submitted to the version control repository directly, but instead is submitted as a shelveset. The build server then grabs the latest version of the code from version control, merges in the changes from the submitted shelveset, and executes the build. If the build succeeds, the shelveset is automatically checked into version control. If the build fails, the developer is given the option to unshelve their code and fix it. Gated builds ensure that the build is never broken, because code can never be checked into the repository until it successfully builds.

The main problem with gated builds is time. If a build takes a long time to execute, and you have large teams checking code in frequently, this can lead to long wait times for builds to complete and code to be checked into the repository. Team Foundation Build 2012 provides a solution to this issue by allowing you to specify a build definition to build more than one queued build at a time -- i.e., to batch the gated builds.

On the Build Definition Trigger tab (Figure 1), you can specify to "merge and build" gated builds, by selecting the Gated Check-in option, and then selecting the Merge checkbox. You will also need to specify the maximum number of build requests to be included in each batch. In Figure 1, this value has been set to 3.

[Click on image for larger view.]
Figure 1. Configuring a batched gated build.

When gated builds are batched, the maximum number of check-ins (specified in the build definition, Figure 1), are merged together and executed as one build. Team Foundation Build has been updated to handle multiple queued builds and build failures. The algorithm works like this:

  • A build starts with all the batched build requests. For example, let's say there are three build requests in the batch.
  • If the build succeeds, all three requests are checked into Team Foundation Version Control, and you're finished.
  • If the build fails, all three build requests are returned to the build queue; but this time they will each be built individually.
  • Each build request will execute individually, allowing the build process to isolate which request(s) caused the earlier build failure
  • Those requests that succeed in building will be checked in, while those that fail will be rejected.

A potential drawback to this method is that if a batched build fails, you'll end up building the application more times than you would have if you didn't batch at all. Therefore, you should strive to keep the batch size to a small, manageable number, such as five or less. Figure 2 shows the results of a batched gated build.

[Click on image for larger view.]
Figure 2. Results of a batched gated build.

You can see that a batched build ran, and failed, so all the check-ins were initially rejected. Then each request was run individually. Two of them failed, but one of them passed. If you open the passing build, there is a Request Summary section, listing the build request that triggered this build. If you click the build request in this section, it will open a new view, called the Build Request View, shown in Figure 3.

[Click on image for larger view.]
Figure 3. The Build Request view.
This view looks very similar to the Build Details view, but contains information specifically about a build request. In looking at Figure 3, you can see this build request was initially built as part of a batch, but failed. When it ran again the second time, it succeeded, and the check-in was committed to the repository.

Gated builds ensure that the code stored in Team Foundation Version Control will always compile. Batched gated builds enhance this functionality even more, by providing a solution to the problem of large queues and long wait times normally associated with gated builds.

About the Author

Mickey Gousset spends his days as a principal consultant for Infront Consulting Group. Gousset is lead author of "Professional Application Lifecycle Management with Visual Studio 2012" (Wrox, 2012) and frequents the speaker circuit singing the praises of ALM and DevOps. He also blogs at ALM Rocks!. Gousset is one of the original Team System/ALM MVPs and has held the award since 2005.

comments powered by Disqus


  • Death of the Dev Machine?

    Here's a takeaway from this week's Ignite 2020 event: An advanced Azure cloud portends the death of the traditional, high-powered dev machine packed with computing, memory and storage components.

  • COVID-19 Is Ignite 2020's Elephant in the Room: 'Frankly, It Sucks'

    As in all things of our new reality, there was no escaping the drastic changes in routine caused by the COVID-19 pandemic during Microsoft's big Ignite 2020 developer/IT pro conference, this week shifted to an online-only event after drawing tens of thousands of in-person attendees in years past.

  • Visual Studio 2019 v16.8 Preview Update Adds Codespaces

    To coincide with the Microsoft Ignite 2020 IT pro/developer event, the Visual Studio dev team shipped a new update, Visual Studio 2019 v16.8 Preview 3.1, with the main attraction being support for cloud-hosted Codespaces, now in a limited beta.

  • Speed Lines Graphic

    New for Blazor: Azure Static Web Apps Support

    With Blazor taking the .NET web development world by storm, one of the first announcements during Microsoft's Ignite 2020 developer/IT event was its new support in Azure Static Web Apps.

  • Entity Framework Core 5 RC1 Is Feature Complete, Ready for Production

    The first release candidate for Entity Framework 5 -- Microsoft's object-database mapper for .NET -- has shipped with a go live license, ready for production.

Upcoming Events