Multiple ways to Install Team City on Ubuntu?

Reading Time: 3 minutes

In this post I will detail the steps on how to install and configure Team City on a Ubuntu server.

Java Installation

TeamCity Server is a JVM web application that runs in a Tomcat application server. It requires a Java SE JRE installation to run.  I have JAVA installed in my system. So I will be Moving ahead.

Install Team City

First of all, I’ll advise you to create one, by executing the following command:

sudo mkdir /Desktop

Now Navigate to the Desktop

cd /Desktop

Next Download the latest Version of Team City

Download the Linux Tar file either manually or through wget command, Further If you Downloaded then Extract that tar file.

To install the TeamCity server, unpack the TeamCity<version number>.tar.gz archive.

You can use the tar xfz TeamCity<version number>.tar.gz command under Linux.

Ensure that JRE or JDK are installed and the JAVA_HOME environment variable is pointing to the Java installation directory .

Now Since I have downloaded a tar file, Further you can extract the contents with this command on ubuntu

tar -zxvf TeamCity-2021.2.1.tar.gz  

Now since we have all the files after extracting the folder, Next we will start the server

Start Server

If TeamCity is installed using the .exe or .tar.gz distributions, it can be started and stopped by the teamcity-server scripts located in the /bin directory. The scripts accept run (run in the same console), start (start a new detached process and exit from the script), and stop commands.

To start/stop the TeamCity server and one default agent at the same time, use the runAll script.

Now after starting teamcity server, You can Start TeamCity UI

Launch TeamCity UI

The TeamCity UI can be accessed via a web browser. The default addresses are http://localhost/ for the exe distribution and http://localhost:8111/ for the tar.gz distribution.

Now Next Method of Installing Team City is through Docker.

Downloading Team City with Docker

First of all we will download the server image from docker hub with

docker pull jetbrains/teamcity-server

Use the following command to start a container with TeamCity server

docker run -it --name teamcity-server-instance  \
    -v <path-to-data-directory>:/data/teamcity_server/datadir \
    -v <path-to-logs-directory>:/opt/teamcity/logs  \
    -p <port-on-host>:8111 \
    jetbrains/teamcity-server

where

  • <path-to-data-directory> is the host machine directory to serve as the TeamCity Data Directory where TeamCity stores project settings and build results. Pass an empty directory for the brand new start. If the mapping is not set, you will lose all the TeamCity settings on the container shutdown.
  • <path-to-logs-directory> is the host machine directory to store the TeamCity server logs. The mapping can be omitted, but then the logs will be lost on container shutdown which will make issues investigation impossible.

Now we will need at least one TeamCity agent to run builds. For that we will use agent image from Docker Hub.

Pull the TeamCity image from the Docker Hub Repository:

jetbrains/teamcity-agent

  and use the following command to start a container with TeamCity agent running inside

docker run -it -e SERVER_URL="<url to TeamCity server>"  \ 
    -v <path to agent config folder>:/data/teamcity_agent/conf  \      
    jetbrains/teamcity-agent

  where <url to TeamCity server> is the full URL for TeamCity server, accessible by the agent. Note that “localhost” will not generally not work as it will refer to the “localhost” inside the container.
<path to agent config folder> is the host machine directory to serve as the TeamCity agent config directory.

Now we can also Install Team City using Docker Compose File Instead

version: '3.1'


# Default ${TEAMCITY_VERSION} is defined in .env file

# ./buildserver_pgdata - Posgres DB data
# ./data_dir - TeamCity data directory
# ./teamcity-server-logs - logs of primary TeamCity server
# ./agents/agent-1/conf - configuration directory for the first build agent
# ./agents/agent-1/conf - configuration directory for the second build agent

services:
  db:
    image: postgres:latest
    restart: always
    environment:
      - POSTGRES_PASSWORD=teamcity_password
      - POSTGRES_USER=teamcity_user
      - POSTGRES_DB=teamcity_db
      - PG_DATA=/var/lib/postgresql/data
    volumes:
      - ./buildserver_pgdata:/var/lib/postgresql/data
    ports:
      - 5433:5432

  teamcity:
    image: jetbrains/teamcity-server:${TEAMCITY_VERSION}
    ports:
      - "8112:8111"
    volumes:
      - ./data_dir:/data/teamcity_server/datadir
      - ./teamcity-server-logs:/opt/teamcity/logs
    depends_on:
      - db

  teamcity-agent-1:
    image: jetbrains/teamcity-agent:${TEAMCITY_VERSION}-linux-sudo
    privileged: true
    volumes:
      - ./agents/agent-1/conf:/data/teamcity_agent/conf
    environment:
      - DOCKER_IN_DOCKER=start
  teamcity-agent-2:
    image: jetbrains/teamcity-agent:${TEAMCITY_VERSION}-linux-sudo
    privileged: true
    volumes:
      - ./agents/agent-2/conf:/data/teamcity_agent/conf
    environment:
      - DOCKER_IN_DOCKER=start

Here in the case of compose file we have used postgre database.

Conclusion:

This blog was about the different ways through which can download and use Teamcity, Note while accessing the dashboard after running it, you can choose database from the list there, Here in the case of compose file we have used postgres database. If you liked this blog please do share and comment.

References:

https://hub.docker.com/r/jetbrains/teamcity-server/

https://github.com/JetBrains/teamcity-docker-samples

https://www.jetbrains.com/help/teamcity/start-teamcity-server.html

Written by 

Passionate about Technology and always Interested to Upskill myself in new technology, Working in the field of DevOps

Leave a Reply