Automating your build process with Capistrano & TeamCity

I have been using a beta version of JetBrains TeamCity for the past six months and i’ve come to love and loathe some of it’s features. For the past few months, one of the primary uses for using TeamCity has been the ability to run the entire projects tests immediately as someone checks in.

This is a vital component to our development cycle as we are using a TDD approach. This enables not only developers to see how close a feature is to complete but also managers and business people to see exactly whats going on in the project instead of having to rely on what has been said in a ticket.

Recently I was using TeamCity for deployment also, using the simple rake task – however after the project became more and more complex we found the need to implement Capistrano. Capistrano is a quick way to deploy your projects and when combining it with TeamCity you have the distinct advantage of not having to install java on your staging or production servers. The process works by running a Capistrano script, which SSH’s into your staging or production machine and then executes your commands through ssh. This enables you to do alot of things such as run shell scripts and all the other bits and pieces you generally need to do in a typical deployment.

Setting up capistrano on teamcity is actually really simple – and you can even use your one worker machine that you had for testing purposes to do this task also.
Firstly you need to set up a user on your staging or production machine to have ssh passwordless authentication and ensure that your dev/staging machine has access to your git or svn repository. This won’t be covered here but I can wriite an in detail guide for these steps if it’s requested.

Secondly you need to make sure your dev machine can ssh (passwordless) into your staging or production server and test that you can pull down git or svn repository on this particular machine, also make sure trivial things are working – like you can write to your build path.

Next it’s all pretty easy. Make your Capistrano configuration file.
One little caviet to note is that you should put the following line in your config

default_run_options[:pty] = true

This will avoid some really odd :: err] Host key verification failed. messages.
From here, set up a new build in team city and point it to your test machine.  You can then have it point to your VCS Repository, from there the build runner selected should be Command Line.

Under the variables you can use the following:

Command executable: * cap
Command parameters: <environment> deploy

Note: If you want to use environment you can use the following capistrano plugin

Like:
  • Digg
  • Facebook
  • Google Bookmarks
  • email
  • LinkedIn
  • Twitter
  • MySpace

Facebook Comments

Leave a Reply