This article demonstrates how to generate automated builds for source code from multiple branches using Team Foundation Server and Team Builds.
I work for a project where multiple branches of the source code are maintained for various reasons:
- Customizations of the product for particular customers
- Hot fixes for the previous releases of the product
We have the TFS structure:
- Code changes are done in the hot fix branches and later merged into the main branch after testing.
- Compiling source code for multiple branches and generating respective Setups on a regular basis.
- Continuous builds for various modules of the project which will be queued immediately after a developer checks in the code. Nightly builds generate the setup for multiple branches.
We decided to automate this using Team Foundation Server and Team Builds.
Is it possible to write a build definition for one branch and reuse it for multiple branches?
To reuse build definitions for multiple branches, we have to follow some coding standards in build definitions.
Consider this build definition.
In the above code, we used variables to hold the branch name, project name, etc. By doing so, we can reuse the same build definition template for multiple branches.
- To make it easier, we have developed Addin's in Visual Studio. We can branch the code and generate build definitions for the branch automatically.
- In the Addins, we have written TFS custom tasks to generate build definitions for a particular branch.
Using the Code (Visual Studio Add In)
The source code for the AddIn is uploaded here. For ease of use, I have created an MSI setup for the AddIn. Here are the steps for using the Branching AddIn.
Step 1: Download the code, compile and Install the Addin.
Step 2: After successful install, open Visual Studio. Right click on the TFS Project you want to branch. You can see the Addin in the Team Explorer tree. Click on ’Branch for sprint’
Step 3: Source - Select the Team Project and the source path you want to branch from the tree.
Target - Select the Path in the tree where you want to branch to. Enter the branch name.
Click on ”Branch’ Button.
You can compare the TFS before and after branching.
After Branching: Source code is branched and new build definitions are created for the new branch:
Step 5: Clean up the old branches. Right click on the branch you want to clean up. Click on ’Clean’ button. This will clean the remove the builds and the source code from the branch.
For those who are new to TFS, here are some one liners:
Team Foundation Server (TFS)
- Microsoft product which offers source control, data collection, reporting, and project tracking
- Intended for collaborative software development projects
- Available either as stand-alone software, or as the server side back end platform for Visual Studio Team System (VSTS)
- Build server included with TFS
- Can be used by developers to do a complete build of the most recent versions of the software contained in source control
- Analyzes what changes have been made to in source control since the last successful build
- Updates any work items to indicate that progress has been made
- E.g.: If a tester filed a bug work-item against build #17, and a developer checked in a change just prior to build #18 being created, then the bug work-item would be updated to state that the bug has been fixed.
- TFSBuild.proj is the file which drives a Team Build. The Team Build Language is synonymous with the Microsoft build language.
- 25th Feb, 2010: This is the first draft of the application. I will try and update this with some more features.
About Proteans Software Solutions
Proteans, a CAMO group company, is an outsourcing company focusing on software product development and business application development on Microsoft Technology Platform. "Committed to consistently deliver high-quality software products and services through continual improvement of our knowledge and practices focused on increased customer satisfaction.