Tuesday, March 20, 2012

Setting up TeamCity to deploy builds

TeamCity works great as a Continuous Integration server, but after the build is done it doesn’t give you a deployment behavior out of the box. The following steps are a guide to configure TeamCity to perform such task. With the right modifications it can be adapted to different technologies and platforms.

Lets take a simple project as an example. This is a windows service that makes a wake up call to a remote webservice. In TeamCity/Administration create a new project called WakeUpService. Then add a build configuration, this will compile the project and create the artifacts for us. It is a .NET project so the build step of the build configuration will be set to Visual Studio (sln).


Now, we need to add another TeamCity build configuration for that same project but in the build step we can select another build runner, in my case I selected MSBuild (I recommend reading Inside The Microsoft Build Engine for the ones not familiar with MSBuild).


There are then two configurations for the project WakeUp:

  1. WakeUpService: To build the artifacts of the project.
  2. Deploy WakeUpService: To deploy the artifacts built by WakeUpService.



To deploy the same artifacts to different machines we can use the TeamCity build agents. We can install them in each of the computers we want to deploy the code and use them only to execute the deploy builds. The MSBuild task file (build.proj) will be executed in that machine.

In order to deploy we can do the following tasks:

  1. Resolve the artifacts (that are going to be deployed).
  2. Uninstall a previous version of this service.
  3. Replace environment variables.
  4. Execute database scripts.
  5. Copy artifacts.
  6. Install the service.
  7. Tag the build on TeamCity.

In the next blog post I will go through each one of those tasks explaining how to accomplish them.