In any software development project a Continuous Integration/ Continuous Deployment DevOps environment is essential. A recent project I elected to make use of TeamCity & Octopus Deploy all on an Azure stack.
In this post I twill detail the steps on how to install and configure Team City 2017.x on a Ubuntu 16.X server.
¶Install Database software
Team City is able to store TeamCity stores build history, users, build results and some run time data to a number of Relation Database Management Systems(RDBMS) including
- Postrgre SQL
- MySQL
- MS SQL
- Oracle
- Default Internal DB(HSQL)
In my particular case I make use of Postgres SQL, Install Postgres SQL on ubuntu
¶Download & Install Team city
Download the latest TeamCity for linux from Jetbrains.
1 | wget https://data.services.jetbrains.com/products/download?code=TC&platform=linux |
After the download completes unpack the file
1 | tar -xzf TeamCity-2017.1.1.tar.gz |
We will install TeamCity to the opt
so we need to move the TeamCity Directory to /opt/
and set permissions to the user running the TeamCity Application.
1 | sudo mkdir /opt/jetbrains |
$user
the owner of teamcity & teamagent
Configure TeamCity to start automatically with the correct use by creating a script to start and stop TeamCity. We’ll create a simple bash script using the nano
text editor.
1 | sudo nano /etc/init.d/teamcity |
If you are going to running the team city service under username other than the one you are currently installing it with then you will need to replace $user
in the code snippet with that username.
Copy and paste the following ocde into the editor.
1 | !/bin/sh |
Change the permissions required to execute the script and add it to the starup to nesure Team City is started whenever the server is start/restart
1 | sudo chmod +x /etc/init.d/teamcity |
¶Download database driver
The database drivers are usually not included in the TeamCity set up files. We will need to download the PostGres Driver seperately and place them in the /opt/jetbrains/teamcity/.BuildServer/lib/jdbc
folder.
Change into the directory
1 | cd /opt/jetbrains/teamcity/.BuildServer/lib/jdbc |
Download the driver
1 | wget https://jdbc.postgresql.org/download/postgresql-9.5.xxxx.jar |
We are now ready to start Team City and begin the configuration in the Team City UI
1 | sudo /etc/init.d/teamcity start |
Navigate to http://[Server name or IP]:8111
and verify that you see “TeamCity First Start” page.
Congratulations TeamCity is installed continue the steps on the web page to configure it.
¶Teamcity build agent installation
- If you install TeamCity bundled with a Tomcat servlet container, or opt to install an agent for Windows, both the server and one build agent named
Default Agent
are installed on the same machine. This is not a recommended setup for production purposes because of security concerns and since the build procedure can slow down the responsiveness of the webUI and overall TeamCity server functioning. If you need more build agents, perform the procedure described below. - If you need the agent to run a operating system different from the TeamCity server, perform the procedure described below.
- For production installations, it is recommended to adjust the Agent’s JVM parameters to include the
-server
option.
Download build agent archive from your TeamCity server
1 | wget http://your_teamcity.server.com:8111/update/buildAgent.zip |
Unzip it in separate directory
1 | cd /opt/jetbrains/ |
Copy agent’s settings file
1 | sudo cp conf/buildAgent.dist.properties conf/buildAgent.properties |
Edit this file
1 | sudo nano conf/buildAgent.properties |
There are fields which you must update
1 | your TeamCity server address: |
Make bin files executable
1 | sudo chmod u+x bin/*.sh |
Build agent usage
1 | ./bin/agent.sh |
Add build agent to rc.local
for autostart after system reboot
1 | /opt/jetbrains/buildagent/bin/agent.sh start/stop |
The <agent home>/launcher/conf/wrapper.conf
file can also be used to alter the agent JVM parameters.
The user account used to run build agent service must have enough rights to start/stop the agent service, as described above.
¶Automatic Agent Start under Linux
To run agent automatically on the machine boot under Linux, configure daemon process with the agent.sh start
command to start it and agent.sh stop
command to stop it. Refer to an example procedure below
- Navigate to the services start/stop services scripts directory
1 | cd /etc/init.d/ |
- Open the build agent service script
1 | sudo vim buildagent |
- Paste the following into the file
1 | !/bin/sh |
- Set the permissions to execute the file
1 | sudo chmod +x buildagent |
- Make links to start the agent service on the machine boot and on restarts using the appropriate tool
- For Debian/Ubuntu
1 | sudo update-rc.d buildagent defaults |
- For Red Hat/CentOS
1 | sudo chkconfig buildagent on |
- At the end, starting the Build Agent, and Team City will pick it up
1 | sudo /etc/init.d/buildagent start |