Thursday, August 16, 2012

Automate Build from Mercurial Branch using TeamCity

I am using TeamCity for long time but new in mercurial. We were using SVN before but as Mercurial giving us many features like local commit, distributed source control so we moved to Mercurial. I faced few problems while migrating to Mercurial using HTTPS and found a good solution here http://www.zachburlingame.com/2011/11/using-mercurial-over-https-with-teamcity/. SVN has concept of branches and tags to which we are very familiar and it works almost different repository. But for Mercurial branch concept is different. Here each changeset is a branch. However Mercurial also allows us to create a branch from a particular revision within same repository which is called namedbranch (http://mercurial.selenic.com/wiki/NamedBranches).
I have created a WPF test project to show you how we can automate a build from mercurial using TeamCity. The project is very simple which display only current version from AssemblyInfo. We will change the assembly info version number after each release. In initial commit the version is 1.0.0.0. and application is displaying like that
image
Workbench is also very simple. Have only one straight line and also pushed to repository.
image
Now assume that we are giving a release of version 1.0.0.0 so we changed to revision of assembly to 1.1.0.0 and pushed to server. Lets see the Workbench now.
image
A straight line where you can see the in revision 1 I have added Nant file and configure TeamCity automation from default branch. and in revision 2 we committed our release code with comment. And in revision 3 we started working on version 1.1.0.0.
Now I want to make a namedbranch in revision 2 so that I can configure a build in TeamCity. To do that I will update my code to revision 2.  You can use Terminal of hg from Workbenchimage
Here you can see the command where I have updated to revision 2.
image
Now I will create a namedbranch in revision 2 and will also commit this.
image
You can see here revision 4 is created and here Branch name is “TestRelease1.0”
The branches command will show you 2 branches.
image
As this is new branch and does not exist in Server so we have to push this branch to Mercurial server but for that we have to use –new-branch option. Lets do it from Synchronizer.
In Synchronizer there have button “options” you will get a checkbox to allow to create a new branch with your given name of namedbranch.
image
Now if you push it other will see a branch also when they will pull from server.
You can also switch from one branch to another branch using Update command.
image
Now we will create a build configuration in TeamCity so that we can create a release build from Release 1.0.0.0.  I assumed here that you know how to configure a build from Mercurial default branch.
We have to create and attach new VCS Root for namedbranch.
image
TeamCity has option to give namedbranch name while creating a new VCSRoot and it will pull the source code from TestBranch1.0 branch. You can also fix bugs and also implement features in namedbranch and TeamCity will pull all changes from namedbranch.

No comments:

Post a Comment