Get Мaximum from TeamCity Integration through REST API

Working in a team is a great challenge when you need close collaboration between different people of different occupations and specializations. This becomes a real pain when members of a team do not have direct communication or communication is complicated with external factors. Here come special collaboration platforms that leverage the gap between people and create a single environment for peer-to-peer interaction and efficient knowledge or information sharing.

Today we will try to review an environment of TeamCity, JIRA and Confluence integrated into a single ecosystem for quick and easy data retrieval about builds and agents from TeamCity.

So what capabilities does this integration offer to the team of software developers? First of all, Confluence can be used as a collaboration platform listing the latest builds within the appropriate project and configuration. Project Managers and Team Leads can be always aware of the progress on the project and track the current activity on project development. JIRA can be used by developers and quality assurance engineers. Developers can track progress on issues and tasks, and quality assurance engineers can track the completion of development and proceed to testing of functionality.

TeamCity is already bundled with JIRA integration capabilities, but Atlassian JIRA does not have a native tool that can fetch build data and show it in JIRA issues, the same is true and for Confluence. The solution from StiltSoft team allows you to establish full-fledged integration between TeamCity, JIRA and Confluence, in addition to standard integration from JetBrains team available in Teamcity.

In our blog post we will show how you can create tools for fetching data from TeamCity via Rest API and showing this build data in some application.

Connecting to TeamCity Server

TeamCity provides REST API, which powerful capabilities can be used for fetching various data from TeamCity server. You need to send a HTTP request to REST API to fetch the required piece of TeamCity data. In order to get the requested piece of data you need to authorize on the server through one of the following ways:

Once your request has been processed, TeamCity server will return a piece of XML data, which you can further parse and output into your application.

Fetch Useful Build Data

First of all, TeamCity server stores a lot of build data, which is the point of interest #1 for you. Build data contains a lot of useful information about builds, their status, time for execution, completion status of tests and related issues in the issue tracking system. The best way is to fetch builds in batches – 20 or 50 builds per batch. You can use the following request to REST API of TeamCity server:

You can use the received project key and issue number for mapping to the particular issue in the issue tracking system.

Quality assurance engineers can easily monitor the status of each issue and can instantly proceed to functionality testing once the corresponding build with the fix is complete. So they needn’t wait for the development team when someone will resolve this issue in the issue tracking system.

Find Out Available TeamCity Agents

You can also retrieve information about build agents and get the list of the currently active agents. This can be useful for the quality assurance engineer and developers to track availability of the specific build agent at the definite period of time. You can make the following request to display the list of available build agents:

Developers can easily view which build agents are currently in use by other projects and start building the project with another agent. The list of agents can be shown as a gadget on JIRA dashboard or placed as a macro on some Confluence page.

Optionally, you can also get information about the agent pools. Agent pool is a separate group of build agents that are assigned to the specific project for running builds. Any project can be assigned to multiple agent pools. Each build agent can be only assigned to one agent pool. You can run project builds only on build agents from pools assigned to the project. By default, all newly authorized agents are included into the Default pool. Agent pools allow you to bind specific agents to specific projects.

The project manager or team lead can get a simple picture of the project development in JIRA. The project will show the listing of builds and their relations to the created JIRA issues.

Alternatively, the project manager can use a macro on Confluence page and view the committed code changes per branch.

Results

REST API of TeamCity is a powerful and rich-in-features interface for getting build data and showing it in your application or system. It provides simple and easy-to-use requests for fetching data from TeamCity server, and even beginners can quickly start using it for building their custom solutions. Besides retrieving data from TeamCity server, you can also update or delete build data depending on the complexity and requirements of your project.