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

Reader Comments:

Add Your Comments Now:

Your Name:(optional)
Your Email:(optional)
Your Location:(optional)
Comment:
Please type the letters/numbers you see above

.NET Insight

Sign up for our newsletter.

I agree to this site's Privacy Policy.