JetBrains TeamCity is a commercial continuous integration server. TeamCity has a Professional Server license. This means that we can create 20 build configurations and one build agent. If we need more configurations or build agents, we can purchase other licenses. In this section, we will see how to create a build plan with Gradle.
We can download installer software for Mac OS X, Windows, and Linux from the JetBrains TeamCity website. We run the installer software to install TeamCity on our computer. TeamCity is also available as an archive for all platforms. To install the archive, we only have to unpack the contents to a directory on our computer. TeamCity is also available as a WAR file, which can be deployed to a Java web container.
Creating a project
In TeamCity we must create a project with the build configuration we want to be executed. Let's see how we can add a project:
After we install TeamCity, we will open a web browser and go to
http://localhost:8111/
. We can create a new project from the Administration page. We can also define the name of our project and provide a short description:
Creating a new project in TeamCity
We will then click on the Create button to create the project and go to an overview page of our project:
Project overview page
It is time to add a new build configuration. We will click on the Create build configuration button in the Build Configurations section to add a build configuration:
Creating a new build configuration
We will click on the Create button to create the project and go to the version control settings page of our project. Here, we fill in the properties of our local Git repository:
Configuration for version control management
We will click on the Create button to create the project and go to an overview page of our project:
Overview of configuration for version control
We will define the artifacts of our project on the General Settings page. We can define the path of the artifacts in our project in the Artifact paths field. Here, We defined the value build/libs/*.jar in the Artifact paths field.:
Configuration of the artifacts of the project
On the project overview screen, we will click on the Add Build Step button. We are taken to a new screen, where we can select the Runner type of the build. Here, we will select the Gradle runner and click on the Save button:
Defining a new build step with Gradle
We are on the configuration page for the build step now, as shown in the following screenshot:
Configuration for Gradle build step
We can fill a descriptive name for this build step in the Step name field. In the Gradle Parameters section, we can set the tasks in the Gradle tasks field. For our project, we want to invoke the build task, so we will fill build. Note that we can enable Incremental building for multi-project builds. TeamCity will use the buildDependents task.
To set the Gradle version, we will fill the Gradle home path field. Extra command-line parameters can be filled in the Additional Gradle command line parameters field.
If our project has a Gradle Wrapper, we can check the Gradle Wrapper checkbox. TeamCity will then use the gradlew or gradlew.bat scripts, instead of the Gradle home path location, to run Gradle.
Running the project
We can save the build configuration, and we are now ready to run it as follows:
At the top-right side, we can see the Run button with an ellipsis. When we click on the ellipsis, we will get a dialog window with options that we can set before we run the build, as shown in the following screenshot:
Running the project with the Gradle build step
We will leave all the options unchanged and click on the Run Build button.
TeamCity instructs the build agent to run our build configuration. The code is checked from the repository, and the build Gradle task is invoked. On the Projects page, we will see a summary of the build:
Results after running the project
We can click on the project to get more details. The following overview page of the project shows the date of the project build, build agent used, and summary of test results:
More details for a project that has run
If we click on the Tests tab, we will see the tests that have run and the time it took to execute them:
Overview of test results
The Build Log tab page shows the output of the build process. We will see detailed information here:
TeamCity logging for running the project
Finally, on the Artifacts page, we will see the generated JAR files. We can click on the filename and see the contents of the files: