Setting up a CI/CD machine with TeamCity
By: Seyed Alireza Mustafa
Tags: Postgresql, Teamcity, Installation, Ci Cd Pipeline, Ubuntu

CI/CD in a nutshell

Continuous Integration & Continuous Delivery, or CI/CD for short, is a software engineering practice to automate the process of integrating, producing and deploying software application in short time cycles. This helps detect problems earlier during application development and reduces time and costs associated with changes made to the code during incremental updates. This practice requires the project manager to maintain a code repository, automate the build process, enforce a self-testing code policy, require daily commits, building and deploying to test systems often.

Since the early days when Jenkins was the leading platform for CI/CD in 2005, a lot of tools have appeared. Stackify lists 50 tools related to CI/CD. For a comparison, you may see the Wikipedia page or visit this GitHub page.

Installing TeamCity

In this article, we review the steps to set up the TeamCity from JetBrains on an Ubuntu virtual machine. The first step is to download the tarball from the vendor and extract it to a, say /opt, directory.

Next, download the recommended version of Java run-time (JDK or JRE) as the underlying framework for TeamCity. JetBrains recommends a 32-bit JDK 1.8+ from AdoptOpenJDK to be used. Initially, I had difficulty pointing the TeamCity to use the JRE, even when I had set the JAVA_HOME & PATH environment variables correctly:

export JAVA_HOME=/opt/{JDK location where bin exists}

export PATH=$PATH:JAVA_HOME/bin

To avoid any possible problem, please copy the extracted JDK contents to /opt/TeamCity/jre folder.

Next, you have to create a database for use by TeamCity. I used PostgreSQL for two reasons: it’s free of charge, and is compatible with SonarQube 7.9, which I use for source code analysis. The latest versions of SonarQube does not support MySQL server anymore!

Installing PostgreSQL

The installation is very easy. Update the apt repository and install it with apt:

sudo apt update

sudo apt install postgresql

Next, run the command line interface, “sudo -i -u postgres psql” and create a database and user for TeamCity.

CREATE DATABASE teamcity;

CREATE USER tc WITH ENCRYPTED PASSWORD ‘password’ ;

And grant the user all the required rights for management.

GRANT ALL PRIVILEGES ON DATABASE teamcity TO tc;

Then, enter \q to exit the command line interface.

Initializing TeamCity

To run the main service by just type “/opt/TeamCity/bin/runAll.sh start”.

If you want to configure the service to run at start-up, open the /etc/rc.local:

sudo nano /etc/rc.local

And, add the above command inside it, and make sure the file is executable (chown +x /etc/rc.local). Now, open up your Firefox and go to the default service address: http://localhost:8111

TeamCity’s initial page after installation

Choose a data directory and proceed to the next page. You need to select the database type. You can opt for the internal DB or select the PostgreSQL you set up earlier.

Database Selection Page

To connect the TeamCity with a database, the appropriate JDBC connector should be copied to .BuildServer/lib/jdbc folder. To get the PostgreSQL connector download the .jar driver from PostgreSQL page.

Enter Database Connection Info

Next, you need to accept the license agreement and create an administrator account.

Creating the Admin Account

The installation is complete, but that’s just the beginning of another journey with TeamCity! Hope you have a smooth installation process.