Tuesday 18 June 2013

Use Teamcity as the Continuous Integration and Build Management Server

I've been using Teamcity as the continuous integration and build management server for the last few years. Not until recently I tried out Hudson (or Jenkins) as the alternative solution. It is quite frustrated to learn that Hudson, being an open-sourced project, doesn't even support remote build (where I can submit my local changes to Teamcity and run a selected builds, and commit once all the builds are successful).

In the scenario where the project has quite a number of builds for various tests, e.g. unit tests, integration tests, external tests, smoke tests, etc., running these tests with my local changes to check whether I break any existing tests or not is rather crucial in agile development approach, where I always want to have a feedback in the shortest amount of time. Of course, without being able to do a remote run with multiple test suites running in parallel, you may argue that I can still run the test suites locally one by one, and only check in when all the tests pass locally, in which case, Hudson is sufficient enough and it is FREE!

I don't intend to devote my blog to compare Teamcity and Hudson, but given the experiences of using both, I can conclude that Teamcity is no doubt the first choice in terms of CI and build management, as its feature is a perfect match for a developer with TDD (Test-Driven Development) and agile mind set. Having said that, I am gonna demonstrate how easy it is to setup the Teamcity for my project hosted on Git. JetBrains does offer a Teamcity professional version which is FREE and comes with a limit of 20 build configurations and 3 build agents.

Installation

  • Download the latest version for Linux (or whichever suits your OS)

  • Unzip the downloaded file, e.g. tar -zxvf TeamCity-7.1.5.tar.gz
    youyang@monkey-dev-01:/app> ll
    total 12
    drwxr-xr-x  6 youyang users 4096 Mar 22 02:31 monkey
    drwxr-xr-x 12 youyang users 4096 Jun 14 09:31 TeamCity
    drwxr-xr-x 13 youyang users 4096 Jun 15 09:11 TeamCity-BuildAgent
    youyang@monkey-dev-01:/app> 
    

  • start up teamcity, e.g. ./app/TeamCity/bin/startup.sh , on port 8111 by default


  • Configuration

  • browse to http://localhost:8111 to verify that Teamcity has started up successfully, which will take a minute or two before it asks you to setup an admin account

  • once the admin account is created and logged in, go to the Administration menu to create a new Project. Specify name and description on the General tab, shown as below

  • create a new VCS root on the VCS Roots tab, and choose Git (or whatever VCS you use), then fill in the information as shown below

  • go back to the project config, and create a build configuration

  • complete a minimum 3-step configuration for the build. Fill in the build name and description for Step 1; Choose the VCS root specified before in Step 2; Specify the build step with Ant (or other build runners the project is using), as shown below

  • this is the minimum configuration for a project with only one build configuration, which is good enough for the demo

  • Teamcity Agent

  • With a project setup on Teamcity server, we still need to install agents so that we can run the builds on them. Go Administration->Install Build Agents, notice that the link for the zip file distribution is http://monkey-dev-01:8111/update/buildAgent.zip

  • On the machine that you want to install your build agent, wget the zip file from, e.g. http://monkey-dev-01:8111/update/buildAgent.zip, unzip to, e.g. /app/TeamCity-BuildAgent folder

  • create the buildAgent.properties from the template file buildAgent.dist.properties under, e.g. /app/TeamCity-BuildAgent/conf folder

  • setup the following properties in the buildAgent.properties file

  • # name of the agent appearing on Teamcity server
    name=Monkey-Dev-01
    # setup the JDK
    env.JAVA_HOME=/app/monkey/java
    
  • start up the agent in the background by typing "/app/TeamCity-BuildAgent/bin/agent.sh start"

  • Wait a few minutes before your agent shown under the Agents->Connected tab on Teamcity server, as shown below

  • Once the agent is connected, you are ready to run your first build on Teamcity:

  • If you are using Intellij IDE, install the Teamcity plugin so that you can send a remote run to the Teamcity server by selecting which builds to run.