How do we automatically deploy with Mercurial and TeamCity

Few weeks ago we moved from SVN to Mercurial. This transition triggered some changes to our deployment process and we decided to play with something interesting. We decided to implement fully automatic deployment. So the idea:

First of all we have three permanent branches:


  • default, this is a Mercurial name of trunk, main development occurs here. If you need something big you make branch, and after work is complete you merge back to default.
  • staging, this is common place where code is ready for staging lives. In most cases code first appear in default and then get merged to staging. Sometimes if we need fast fix on staging, we do it in staging branch and then merge back to default. We also experimenting with merging code from named feature branches, this scenario works, but requires some communication.
  • live, similar to staging, but dedicated to live. In most cases code comes from staging.

Second is we have TeamCity configured to pull changes from this branches and if something changed automatically build. In case of staging and live branches build also includes deployment to servers. Deployment is implemented using simple Powershell scripts and robocopy.

Easy and it works. Now deployment is just simple commit to the corresponding branch.

Some less important notes:

  1. If after deployment, we found issue and want rollback, two options here. First is reverting changes in corresponding branch (this is easy, because each build has its own commit). Second is using nice “Run custom build” feature of the TeamCity. You just need to select previous commit and run build again.
  2. Messages of the commits to staging and live should be descriptive, as they are gone be the only information you see on build server.
  3. This is easy to write script that will automate sequence of commands to commit to staging or live branch. This is one from me.


. .


  1. chaliy posted this