Friday, May 18, 2012

Install TeamCity Continuous Integration in Ubuntu Linux

Friday, May 18, 2012 Posted by Andre Broers , , , , , , 16 comments
In this post I will install the TeamCity Continuous Integration server in the Ubuntu Linux environment as configured in this previous blogpost. Before we start we have to give the Ubuntu Server a bit more memory as the 512 MB configured. Double it to 1024 MB.

First thing to do is install the latest Java Developers Kit in our Ubuntu server. (I will use the latest openJDK although it is not supported by TeamCity it is much easier to install in Ubuntu and I won't use this configuration for mission critical operations).
me@ubuntu01:~$ sudo apt-get update
me@ubuntu01:~$ sudo apt-get install openjdk-7-jre

After this download the latest TeamCity distribution from the linux tab from http://www.jetbrains.com/teamcity/download/
me@ubuntu01:~$ wget http://download.jetbrains.com/teamcity/TeamCity-7.0.3.tar.gz

Now unpack the distro to this location:
me@ubuntu01:~$ cd /var
me@ubuntu01:/var$ sudo tar zxvf ~/TeamCity-7.0.3.tar.gz

Now start the TeamCity server:
me@ubuntu01:/var$ cd TeamCity
me@ubuntu01:/var/TeamCity$ sudo ./bin/runAll.sh start
Using CATALINA_BASE:   /var/TeamCity
Using CATALINA_HOME:   /var/TeamCity
Using CATALINA_TMPDIR: /var/TeamCity/temp
Using JRE_HOME:        /usr
Using CLASSPATH:       /var/TeamCity/bin/bootstrap.jar:/var/TeamCity/bin/tomcat-juli.jar
Starting TeamCity build agent...
Java executable is found in '/usr/bin/..'.
Starting TeamCity Build Agent Launcher...
Agent home directory is /var/TeamCity/buildAgent
Current Java runtime version is 1.6
Lock file: /var/TeamCity/buildAgent/logs/buildAgent.properties.lock
Using no lock
Done [2761], see log at ../logs/teamcity-agent.log
me@ubuntu01:/var/TeamCity$

Create service start and stop procedures:
me@ubuntu01:/var/TeamCity$ sudo vi /etc/init.d/teamcity

Copy and paste the following:
#! /bin/sh
# /etc/init.d/teamcity
#

# Carry out specific functions when asked to by the system
case "$1" in
  start)
    echo "Starting script teamcity "
    /var/TeamCity/bin/runAll.sh start
    ;;
  stop)
    echo "Stopping script teamcity"
    /var/TeamCity/bin/runAll.sh stop
    ;;
  *)
    echo "Usage: /etc/init.d/teamcity {start|stop}"
    exit 1
    ;;
esac

exit 0

Now add it to the default Ubuntu boot procedure:
me@ubuntu01:/var/TeamCity$ sudo chmod 755 /etc/init.d/teamcity
me@ubuntu01:/var/TeamCity$ sudo update-rc.d teamcity defaults
 Adding system startup for /etc/init.d/teamcity ...
   /etc/rc0.d/K20teamcity -> ../init.d/teamcity
   /etc/rc1.d/K20teamcity -> ../init.d/teamcity
   /etc/rc6.d/K20teamcity -> ../init.d/teamcity
   /etc/rc2.d/S20teamcity -> ../init.d/teamcity
   /etc/rc3.d/S20teamcity -> ../init.d/teamcity
   /etc/rc4.d/S20teamcity -> ../init.d/teamcity
   /etc/rc5.d/S20teamcity -> ../init.d/teamcity
me@ubuntu01:/etc/init.d$

Now you can start and stop the TeamCity server with the service teamcity stop/start command. The TeamCity server will also be restarted after a reboot of your Linux server.

Normally we can now open the TeamCity admin page in our webbrowser at http://127.0.0.1:8111 . But because we have installed our installation in a virtual box virtual machine and we don't have a graphic browser in our Ubuntu server environment so we have to create a Virtual Box port forward to our Ubuntu virtual machine. I described the port forward construct in this blogpost, so I will show the short version here. We have to create a port forward of a local port 8111 to the Ubuntu Virtual Machine at port 8111. To do this you have to shut down your Virtual Machine. (But remember TeamCity will automatically come up after a reboot ;-). Open a command line shell on your workstation and type the following after the shutdown of the Ubuntu virtual machine:
Microsoft Windows [Version 6.1.7600]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\broersa>cd "c:\Program Files\Oracle\VirtualBox"

c:\Program Files\Oracle\VirtualBox>VBoxManage modifyvm "ubuntu01" --natpf1 "gues
tteamcity,tcp,,8111,,8111"

c:\Program Files\Oracle\VirtualBox>

Now restart you Ubuntu virtual machine and point your local browser to http://127.0.0.1:8111 .


 
Click proceed and your new server is starting for the first time.

16 comments:

  1. Very helpful. Thanks

    ReplyDelete
  2. Thank you for the post Andre Broers. I have Teamcity (where our builds happen everyday) on Windows. Now, I need to install second one, "Teamcity build agent" on Linux (Ubuntu). Can I follow this method or do i have to do anything addition to this. Many thanks for your help. Appreciate it.

    ReplyDelete
    Replies
    1. Thanx for your comment. It's been a while I did this blogpost. Since then I started using Jenkins. I don't know if it is stil complete up to date. Try it out on a test linux distro first.

      Delete
  3. Hey Andre, Hey Andre, Can tell please why did you switch to Jenkins? Thanks for your help.

    ReplyDelete
  4. Hi,

    Is there a way to start build agent as a different user than root?

    ReplyDelete
  5. Really nice post. Unix is a multiuser and multi tasking operating system at the same time. Unix Training Chennai offering real time Unix course at reasonable cost.

    ReplyDelete
  6. A discussion exists amongst industry spectators regarding whether Twitter has truth be told been snappier than customary media outlets for breaking news about town agent services.

    ReplyDelete
  7. Great Article… I love to read your articles because your writing style is too good, its is very very helpful for all of us and I never get bored while reading your article because, they are becomes a more and more interesting from the starting lines until the end.
    LINUX Training in Chennai

    ReplyDelete