Book Image

Learning Continuous Integration with TeamCity

Book Image

Learning Continuous Integration with TeamCity

Overview of this book

Table of Contents (19 chapters)
Learning Continuous Integration with TeamCity
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Introduction to TeamCity


TeamCity is a CI server from JetBrains and comes with a lot of features out of the box to get you started quickly with CI for your projects.

As a CI server, TeamCity can detect changes in version-control repositories and trigger builds whenever new code is checked in. TeamCity can be configured to perform the build activities, which includes the compilation of source code, running unit tests and integration tests, deploying the built executables into a testing environment to perform functional tests, and exposing artifacts for downloads.

TeamCity is designed to help you follow the best practices of CI. With its ability to download artifacts from another build configuration, for example, TeamCity enables you to follow the approach of build once and deploy everywhere. TeamCity is feature-rich and flexible enough to allow you to follow the practices that suit your team and your needs the best.

This book will be using TeamCity 8.0.x, but we will also be looking at some of the newer features of the 8.1.x release.

Licensing

Before we get all excited about the amazing features that TeamCity brings to the table, it is worthwhile to explore the licensing options available. TeamCity is a commercial product from JetBrains, but the licensing options are designed so that small teams can get started with TeamCity for free.

TeamCity comes with the Professional Server License for free. It allows you to run a TeamCity server, which can have up to 20 build configurations, and use three build agents. In my experience, this is pretty sufficient for small projects. Teams can easily start their CI setup with TeamCity, and if they find a need for more configurations/agents later, they can do so at that point in time. Additional agents can be bought separately, which also bumps up the maximum number of build configurations allowed by 10 each.

For bigger teams and projects, there is Enterprise Server License. This license enables you to have unlimited build configurations and agents with your TeamCity server. This also includes upgrades to the latest version of TeamCity for a year.

JetBrains also provides Open Source License, which is given for free to noncommercial open-source projects that qualify. This license is similar in features to the Enterprise Server License mentioned previously.

You can read up about the latest TeamCity licensing options at http://www.jetbrains.com/teamcity/buy/.

Features

With the licensing options discussed, it's time to talk about the goodies that TeamCity comes with. As previously mentioned, TeamCity is feature rich. This section will focus on highlighting the most important features of TeamCity, especially with respect to the overall aim of setting up an effective CI.

First-class support for various technologies

TeamCity comes with great support for various technologies such as Java, .NET, Ruby, Android, iOS, and much more.

For example, if you have a .NET project that uses the Powershell-based PSake framework for its build, you can use the Powershell runner to run your build off a PSake build script.

The ability to support most platforms/technologies with very well thought out and first-class features make TeamCity a valuable tool to help you quickly get started with your CI setup.

Lots of plugins

This first-class and extensive support doesn't imply that TeamCity doesn't have or can't have plugins. It has quite a lot of them and for various purposes. Both JetBrains, and the community at large write plugins for TeamCity. Many of these plugins come bundled with TeamCity itself.

Many of these plugins are very useful and some of them are downright cool. A more recent plugin adds torrent abilities to TeamCity so that agents can download artifacts using the BitTorrent protocol, when appropriate.

A comprehensive list of available plugins can be found at http://confluence.jetbrains.com/display/TW/TeamCity+Plugins.

REST API

TeamCity comes with a REST API, which itself is a bundled plugin, that you can use to perform remote actions such as triggering builds, getting the status of running builds, and downloading artifacts among others. Depending on the particular requirements of your CI setup, the REST API can prove to be very valuable.

Comprehensive VCS support

As mentioned in the section where CI was introduced, version control system (VCS) plays an important part in CI. CI servers must support a wide range of VCSes, and must provide for flexible configurations that cater to the team's needs.

Note

We will be looking at VCSes in detail, and the role that they play in CI, in Chapter 3, Getting Your CI Up and Running

TeamCity supports almost every major VCSes such as Git, Mercurial, Subversion, CVS, Microsoft Team Foundation Server, and Perforce. TeamCity enables you to view the changes from the VCS for each of your builds and also provides high-fidelity diff views right in the browser. Triggering builds by looking at the changes in VCS can be fine-tuned to any extent. For example, you can avoid builds being triggered if changes happen within a particular directory in your repository, with other directories triggering builds as normal.

A nice dashboard UI and build history

Another important CI practice that TeamCity enables centers on the visibility and tracking of what is happening and what has happened. TeamCity provides a nice dashboard view of the projects and the build configurations in which builds are running, failing, and so on. The following screenshot of a TeamCity demo server gives a good view of the typical state of TeamCity's overview page:

With user management features such as authentication and audit, it becomes easy to track who did what. A user can communicate, for example, if they are working on fixing broken builds. Other users can also assign people who are/have to investigate the broken builds.

TeamCity provides lots of features to track historical data of builds. With the help of statistical reports and graphs, you can quickly learn about the various characteristics of a build, such as build time and number of tests.

We can also set up and fine-tune how historical data is cleared up or preserved through the Build History Clean-up features. Builds that are promoted, to say production, can be pinned for eternity. Builds that ran a few days or even a few months ago (called history build) can be replicated, if needed.

Ease of setup and comprehensive documentation

All the features that TeamCity offers would be for naught if TeamCity makes it very difficult for you to make use of them. Thankfully, this is not the case. Getting started with your CI setup is a breeze with TeamCity. The configuration interface to set up projects and build configurations is straightforward. The main configuration items are clearly highlighted, and more advanced ones are available under the right levels of nesting.

TeamCity also provides features such as templates, a set of common settings from which build configurations can be quickly spawned that make it extremely easy for you to set up more and more build configurations.

The simplicity and power of TeamCity can be explained with one of my most favorite features. When you enable NuGet support in TeamCity, you can double up TeamCity as a NuGet repository feed by simply publishing the NuGet packages as artifacts; simple and intuitive!

TeamCity is also well documented and has a huge community of users around it. This makes it very easy for teams starting with TeamCity to make the right decisions when setting up their CI.

Build pipeline/chains

As mentioned previously, build pipelines are the ideal way to set up CI (and CD) for your projects. TeamCity has built-in support for such pipelining/chaining of build configurations.

Using the Snapshot dependency feature in TeamCity, we can easily configure build chains / build pipelines. TeamCity also comes with a nice visualization for build chains. The following screenshot shows one such build chain:

Agents and build grids

TeamCity comes with all the bells and whistles to manage a build farm or grid of agents. TeamCity makes it a breeze to manage tens, hundreds, or even more agents that may exist in the build grid. TeamCity can provide workload statistics, distribute load across agents, enable you to run builds on all the agents or only specific agents, and more. The following screenshot shows the Load Statistics Matrix of a demo TeamCity server:

Also, with its Amazon EC2 integration, TeamCity can spin up VMs on EC2 and run the builds and bring them down as and when needed.

TeamCity doesn't even mandate all the agents to have the version control tool configured, as the server can do the checkout and send the files over. The server can also upgrade agents automatically.

IDE integrations

TeamCity has very well thought out integrations with various IDEs such as IntelliJ IDEA (another JetBrains product) and Visual Studio. Through the TeamCity plugins for these IDEs, it is possible to look at the status of the builds, the reason for the failures, and even trigger and pause builds without having to leave the comfort of the IDE.

Additional features such as precommit and personal builds are available through such IDE plugins.

The preceding set of features only scratches the surface of TeamCity. TeamCity has a lot more to offer. We will be exploring these and many other features of TeamCity in the coming chapters.