Exploring TeamCity: Your Path to DevOps Success Without Breaking the Bank

Shrihari Haridas
8 min readOct 28, 2023

--

Resource: TeamCity

TeamCity is a Continuous Integration and Continuous Deployment (CI/CD) platform that helps developers automate and streamline the process of building, testing, and deploying software.

What sets TeamCity apart for beginners is its user-friendly interface and robust feature set. It offers easy setup, supports various programming languages and build tools, and provides insightful feedback on code quality.

Plus, it’s free for small projects, making it an excellent choice for those starting their DevOps journey.

Context:

TeamCity is a user-friendly CI/CD platform that’s perfect for beginners. Today, we’ll focus on creating a CI pipeline. We’ll take Java application code, use Gradle to build it, create a Docker image, and then push that image to a Docker Hub repository. This step-by-step guide will help you automate your software delivery process effortlessly.

===============================================================

  1. Begin by logging into your AWS account, where you’ll proceed to launch a single EC2 server of type ‘t2.medium.’ Additionally, ensure that port 8111, used by TeamCity, is open for access.”

2. Next, establish a connection with the server you just launched and proceed to install Docker. Don’t forget to perform a system update for your machine as well.

sudo su
apt-get update
apt-get install docker.io -y

3. Now, let’s proceed with the installation of TeamCity inside a Docker container.

docker run \
-v team_city_data:/data/teamcity_server/datadir \
-v team_city_logs:/opt/teamcity/logs \
-p 8111:8111 \
-d jetbrains/teamcity-server

4. Copy the public IP address and access it using the port number ‘8111’ in your web browser.

5. Click the ‘Proceed’ button, and you’ll be presented with a database selection option. Choose the default option ‘Internal,’ and then click ‘Proceed’.

6. After accepting the ‘Terms & Conditions’ and setting up the ‘Admin’ account, you will be presented with the following window.

7. Now, click the ‘Create Project’ button and proceed to clone a project from GitLab that contains Java code. Your next step is to build this code and push it into Docker.

https://gitlab.com/nanuchi/java-app.git

8. You’ll notice that the connection to the repository is successful. Leave the options as default and proceed by clicking ‘Proceed’.

9. As shown in the image below, TeamCity automatically detects the necessary commands or steps to execute. However, to tailor the configuration to our specific needs, click on ‘Configure build steps manually’ highlighted in blue on the right side.

10. In the build step, search for ‘Gradle’ to build the code.

11. After selecting ‘Gradle,’ you will see a configuration section where you should input the following values.

12. In the ‘Gradle’ task, use the ‘clean’ and ‘build’ commands, separating them with a space, and then save the configuration.

13. With the first build step completed, proceed to add another build step by clicking on ‘Add build step.’ Choose ‘Docker’ as the option and continue.

14. In the Docker configuration, set the values as shown above. For the Dockerfile path, click on the blue option to access your repository files and select ‘Dockerfile’.

15. Before proceeding to the next step, log in to your Docker repository and create a private repository where you will push the Docker image.

16. Now, return to the TeamCity page as we configure Docker. Keep in mind that you can push multiple images into the repository.

17. Finally, save the configuration.

18. Once more, click on ‘Add build step,’ and this time select ‘Docker.’ We will use this step to push the image to the Docker repository.

19. Save these settings. Note that if you click on the ‘Advanced’ option, you will find the ‘Execute Step’ option.

20. Now, since TeamCity isn’t aware of Docker Hub, we need to establish a connection between TeamCity and ‘Docker Hub.’ Additionally, as our repository is private, we must configure the necessary settings for that.

21. So, click on ‘Java-App’.

22. Click on the ‘Connection’ option on the left-hand side.

23. Next, click on ‘Add connection,’ and then select ‘Docker Hub Registry.

24. Add your Docker credentials, test the connection, and save it.

25. Return to the ‘Build Configuration,’ and this time, click on ‘Build Feature.

26. Click on ‘Add Build Feature,’ select ‘Docker Support,’ then click ‘Add Registry Connection.’ Choose ‘Docker Registry,’ click ‘Add,’ and finally, ‘Save’.

27.This step is crucial because, after a successful build, it will automatically log in to the ‘Docker Registry’.

28. Now, let’s configure ‘Build Agents,’ where all the steps will be performed. Currently, we have ‘0’ agents available.

29. Now, the question is how to deploy build agents, and there are three options available:

A. Install on OS

B. Run as Docker Container

C. In TeamCity cloud, suitable agents are managed for you

For this setup, we’ll choose option ‘B,’ which is to run as a Docker container. To achieve this, use the following Docker command:

30. start TeamCity agent without docker volume mount

docker run -e SERVER_URL="http://public-ip:8111"  \
-v team_city_agent_config:/data/teamcity_agent/conf \
-e SERVER_URL="Public IP"
-d jetbrains/teamcity-agent

start TeamCity agent with docker volume mount

docker run -e SERVER_URL="http://54.157.169.25:8111"  \
-v team_city_agent_config_two:/data/teamcity_agent/conf \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /var/lib/docker:/var/lib/docker \
-d jetbrains/teamcity-agent:2021.1

31. Now, reconnect to the server to execute the following command.

32. If you return to the TeamCity UI and check the ‘Agents’ section, you’ll notice that we still have ‘0’ authorized agents but there is ‘1’ unauthorized agent visible.

33. Click on the IP address and ‘Authorize’ the agent.

34. Now, let’s explore how to connect the agent with the TeamCity server using Docker.

35. Now, navigate to the ‘Project’ section and access the ‘Build’ option.

36. Next, click on ‘Compatible Agent’.

37. Currently, our deployed agent is ‘Incompatible,’ but we require a ‘Compatible’ agent to execute the build.

38. Now, let’s deploy another agent, but this time we will mount a Docker on the host inside the container.

docker run -e SERVER_URL="http://Public IP :8111"  \
-v team_city_agent_config_two:/data/teamcity_agent/conf \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /var/lib/docker:/var/lib/docker \
-d jetbrains/teamcity-agent:2021.1

39. If the command below produces an error, please locate the actual path of Docker on your system. It’s not guaranteed that your Docker files are stored inside /usr/bin/docker. As you can see in my output, my files are stored in /var/lib/docker, and you may find multiple files inside.

40. Now, go back to the ‘Agents’ section, and you will find one ‘Unauthorized Agent.’ Proceed to authorize it in the same way as we did in previous steps.

41. Now, return to ‘Java’ > ‘Build’ > ‘Compatible Agents,’ and you’ll notice that our agent is now marked as ‘Compatible.

42. This indicates that we can now execute our build. To do so, click on the ‘Run’ option located in the top-right corner of the same page.

43. If everything is set up correctly, you will observe that your build has been successful.

44. Our demo is successful!

45. As an additional tip in line with the latest trends, if you prefer to write code configurations, click on the ‘View as Code’ option. You can make edits directly from there.

Conclusion:

In this guide, we’ve learned how to set up a CI/CD pipeline using TeamCity, an accessible tool for beginners. From launching an EC2 server on AWS to configuring build steps, creating Docker containers, and connecting agents, TeamCity streamlines the DevOps journey. It’s cost-effective for small projects, making it an ideal choice for those new to DevOps. With Git integration, Docker support, and code-based configurations, TeamCity equips you with essential DevOps skills. Mastering TeamCity accelerates your path as a DevOps engineer.

Resources:

  1. TeamCity: TeamCity: the Hassle-Free CI/CD Tool by JetBrains

2. YouTube: https://youtu.be/zqi4fDF-S60?si=gi_uJ98hHwG0Ui77

--

--

Shrihari Haridas

Hello everyone, I am Shrihari Haridas I am a Cloud & DevOps Engineer, I work with most of DevOps Tools like, Jenkins, Git, Docker, etc.!& for Cloud AWS