Skip to content

Instantly share code, notes, and snippets.

@DamienBraillard
Last active October 14, 2024 16:18
Show Gist options
  • Save DamienBraillard/bd7aa597ccf7a60a3aaa8004c10640b7 to your computer and use it in GitHub Desktop.
Save DamienBraillard/bd7aa597ccf7a60a3aaa8004c10640b7 to your computer and use it in GitHub Desktop.
TeamCity setup under Ubuntu

Installing TeamCity

Install MySql

Install and secure MySql isntallation:

apt install mariadb-server
mysql_secure_installation

Setup the MySql database for TeamCity:

Start the MySql client:

mysql -u -p <Root Pasword entered during mysql_secure_installation>

Then issue the following commands:

create database teamcity collate utf8_bin;
create user teamcity identified by '<any password of your choice>';
grant all privileges on teamcity.* to teamcity;
grant process on *.* to teamcity;

Remember the password you selected, it will be needed when setting up TeamCity later.

Install the Java runtime 8

Install the Java JDK 8

apt install openjdk-8-jdk

Configure the JAVA_HOME environment variable

echo JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64/ >> /etc/environment 
source /etc/environment

Create a user to run TeamCity

Execute the following command and answer to the questions:

adduser teamcity

Download and extract TeamCity

Go to the TeamCity download page for linux.

When the download starts, cancel the download. Then, copy the download link labelled "Direct Link".

Setup the folders, download and extract from the linux machine:

mkdir /opt/JetBrains
cd /opt/JetBrains

wget <The download link you copied before>

tar -xzvf TeamCity*.tar.gz

chown -Rv teamcity:teamcity TeamCity

Setup NGINX so that you can access TeamCity from outside your build server

Install NGINX:

sudo apt-get install nginx

Create and enable the NGINX TeamCity site:

cat << EOF > /etc/nginx/sites-available/teamcity
# We need to support websockets from TC 9.x onwards
# https://confluence.jetbrains.com/display/TCD9/How+To...#HowTo...-SetUpTeamCitybehindaProxyServer

map $http_upgrade $connection_upgrade {
    default upgrade;
    ''   '';
}

server {

    listen 80 default_server;
    server_name _;

    proxy_read_timeout     1200;
    proxy_connect_timeout  240;
    client_max_body_size   0;

    location / {

        proxy_pass          http://localhost:8111;
        proxy_http_version  1.1;
        proxy_set_header    Host $http_host;
        proxy_set_header    X-Forwarded-Host $http_host;    # necessary for proper absolute redirects and TeamCity CSRF check
        proxy_set_header    X-Forwarded-Proto $scheme;
        proxy_set_header    X-Forwarded-For $remote_addr;
        proxy_set_header    Upgrade $http_upgrade;
        proxy_set_header    Connection $connection_upgrade;
    }
}
EOF

sudo ln -s /etc/nginx/sites-available/teamcity /etc/nginx/sites-enabled/teamcity

sudo rm -rf /etc/nginx/sites-available/default
sudo rm -rf /etc/nginx/sites-enabled/default

sudo service nginx restart

Setup a start script so that TeamCity starts automatically at boot

Setup the startup script

cat <<EOF > /etc/init.d/teamcity
#!/bin/sh
### BEGIN INIT INFO
# Provides:          TeamCity autostart
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start teamcity daemon at boot time
# Description:       Enable service provided by daemon.
# /etc/init.d/teamcity -  startup script for teamcity
### END INIT INFO
 
 
#  Ensure you enter the  right  user name that  TeamCity will run  under
USER="teamcity"
 
#  Uncomment and set to the data path to be used by TeamCity 
#export TEAMCITY_DATA_PATH="/opt/JetBrains/TeamCity/.BuildServer"
 
case $1 in
 
start)
  start-stop-daemon --start -c $USER --exec /opt/JetBrains/TeamCity/bin/runAll.sh start
 ;;
stop)
  start-stop-daemon --start -c $USER  --exec  /opt/JetBrains/TeamCity/bin/runAll.sh stop
 ;;
 esac
 
exit 0

EOF

chmod +x /etc/init.d/teamcity
update-rc.d teamcity defaults

Start TeamCity:

/etc/init.d/teamcity start

Configure TeamCity for first start

Connect to the TeamCity web interface

On your machine, open the TeamCity web site (http://your-build-server).

  1. Verify that the data directory is correct. If not, set the TEAMCITY_DATA_PATH environment variable in the /etc/init.d/teamcity script and restart TeamCity.
  2. Select MySql as the database type.
    1. Click [Download JDBC Driver]
    2. Enter the following values for the connexion
      • Database host: leave empty
      • Database name: enter teamcity
      • User name: enter teamcity
      • Password: enter the password you selected while creating the teamcity MySQL user
  3. Wait until initialize completes. This might take some time...
  4. Accept the licence agreement
  5. Create the admin account
  6. Complete your profile and done !
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment