We can drive the whole process of customization from consulting and planning to development and support. Don't be satisfied with what you have. Always find a way to extend your possibilities. Write us

How to Integrate TeamCity and Bitbucket Server

Bitbucket (formerly Stash) is a centralized development management solution for controlling your repositories behind the firewall. It allows you to simplify the procedures of hosting an internal source code control server and provide easy access to your repositories for all your team members.

In IT world, it is not a secret that Bitbucket can be integrated with other software products and platforms into a single ecosystem that makes the entire development process comprehensive and convenient. Most times, people integrate Bitbucket with JIRA. But localization and resolution of the issue is not the only problem, which a generic development encounters every day, several times a day. But it is more important to preserve the project integrity while adding modifications or corrections into the program code. For these purposes, you can use the continuous integration server that can also create project builds and run a series of test for automatic verification of functionality.

Bitbucket provides out-of-box integration with the Atlassian native solution - Bamboo. But besides Bamboo, there are other CI solutions which are also quite popular - TeamCity and Jenkins. In our blog post we will outline the specifics of integrating Bitbucket and TeamCity.

REST API as an integration point with Bitbucket

Since times when Bitbucket received support for REST API, it has become much easier to work with and develop custom solutions for it. Now there are several add-ons that allow you to integrate the continuous integration with Bitbucket and get information about status of builds. While viewing commits in the repository, you can instantly see the status of the build or seamlessly proceed to TeamCity for identifying the issues occurred in the particular commit, or just download the latest version of the application for the customer.

Tools to integrate TeamCity and Bitbucket

On the Internet you can find two add-ons for TeamCity that can be used for integration with Bitbucket. Commit Status Publisher is being developed by JetBrains, the other - TeamCity Stash Integration - is being developed by the developer known as mendhak. Both add-ons have proved to be reliable tools for integrating TeamCity and Bitbucket. Let’s review both of them and find their pros and cons.

Installing add-ons in TeamCity

Installation of the add-ons in TeamCity is quite simple and is performed in a normal way as described in documentation. Just upload ZIP-archives with the add-ons through the administration console of TeamCity, then restart the server and that’s done. Add-ons are available and ready to show your the necessary data.

teamcity_addon_installation

Commit Status Publisher from JetBrains

First of all, we would like to present the native add-on from the developers of TeamCity because native integration tools are usually convenient, well-thought and rich in features. You need to configure the build in TeamCity and enable transfer of its status to Bitbucket.  For this purpose, you need to add a Build Feature with Commit status publisher type, which becomes available after installation of the add-on. Complete the configuration of connection to Bitbucket.

commit_status_publisher_configuration

Once the configuration is complete, run the application build and ensure that Bitbucket received data from TeamCity.

viewing_commit_data_mappings_and_changes

When you click the build icon, the form with information about the project, configuration and build number is opened. You can see the number of passed and ignored tests.

viewing_build_details

While viewing the pull request details, you can also open the form with details on the build.

viewing_build_details_in_bitbucket

TeamCity Stash (Bitbucket) Integration from mendhak

Configuration of the add-on is similar to the one from JetBrains. After installation, a new build feature becomes available - Report build status to Atlassian Bitbucket. Unlike the add-on from JetBrains, there are more settings. For example, you can mark the canceled builds as failed in Bitbucket, or you can show status of the latest build for each instead of showing all statuses for each commit.

teamcity_stash_integration_addon_mendhak

Once the piece of code is committed, you can view the commit status for all the associated builds and their statuses.

build_to_commit_mapping_viewing

Which add-on to choose?

It is necessary to point out that these two add-ons are quite similar.They use Bitbucket REST API for fetching status of builds. Installation and configuration of both add-ons is quite simple. Pros for the native add-on from JetBrains include compatibility with future TeamCity versions, instant release of the add-on update with the release of TeamCity and support from the well-known development team. TeamCity Stash Integration add-on has a bit more functions and detailed instructions to configure the add-on. Which the add-on to choose depends on your requirements and personal preferences.