How to integrate TeamCity and Bitbucket Server
- Transfer

Bitbucket Server (formerly known as Stash) is a solution for centralized development management that allows you to manage your repositories, including without opening access to them from outside the organization. Bitbucket makes it easy to store source repositories on your server and provides easy access to repositories for all members of your team.
In the IT world, it is known that Bitbucket can be integrated with other products and platforms into a single ecosystem that makes the development process comprehensive and convenient. Most often, Bitbucket integrates with JIRA.. However, the search and localization of problems is not the only task that the typical development process faces every day, and even several times a day. A more important task is to maintain the integrity of the project in the process of making additions and corrections to the code. For these tasks, you can use the CI server, which also allows you to create builds of projects and run a series of tests to automatically check the functionality.
“Out of the Box” Bitbucket offers integration with Atlassian's sister solution , Bamboo . But, in addition to Bamboo, there are other CI solutions that are also quite popular - TeamCity and Jenkins . In our post, we outline the specifics of integrating Bitbucket and TeamCity.
REST API as a point of integration with Bitbucket
Since Bitbucket acquired the REST API (in fact, Stash always had it and expanded as the functionality of the Stash / Bitbucket Server itself grew - comment of the translator), it has become much easier to work with and build solutions for each a specific case. Currently, there are several add-ons for integrating Bitbucket with CI-systems and obtaining information about the status of assemblies. By examining the commits in the repository, you can simultaneously see the build status and easily go to TeamCity to study the problems encountered when building a particular commit, or simply download the latest version of the application for the client.
Tools for integrating TeamCity and Bitbucket
On the Internet, you can find two plugins for TeamCity that can be used to integrate with Bitbucket. Commit Status Publisher was released directly by JetBrains , another - TeamCity Stash Integration - was developed by mendhak . Both have proven their ability to integrate Teamcity and Bitbucket. Let's take a look at each of them and look for their pros and cons.
Install plugins in Teamcity
Installing plugins in TeamCity is quite simple and is performed in accordance with the documentation . We download zip archives with plugins through the Teamcity administrative console, restart Teamcity. Plugins are available and ready to help you get the information you need.

JetBrains Commit Status Publisher
First of all, we will introduce a “native” plug-in from the developer of TeamCity itself, since integration tools “from the developer” are usually convenient, thoughtful and functional. Configure the build to transfer build status to Bitbucket. To do this, add the Build Feature with the type Commit status publisher (this type becomes available after installing the plug-in from JetBrains). Finish connecting to Bitbucket.

After completing the setup, run the build and make sure that Bitbucket received the data from TeamCity.

By clicking on the assembly icon, a window opens containing information about the project, configuration and assembly number. The number of tests passed and ignored is also displayed.

When viewing pull request details, you can also open a form with assembly information in the same way.

Teamcity Stash (Bitbucket) integration by mendhak
The plugin is configured similarly to the solution from JetBrains. After installation, a build feature appears called Report build status to Atlassian Bitbucket. Unlike the JetBrains addon, more options appear. You can, for example, mark a canceled build in Bitbucket as unsuccessful. Or, do not show the statuses of all assemblies in Bitbucket, leaving only the status of the last assembly for each commit.

After committing the code, you can see the builds that depend on this commit and their status.

Which plugin to choose?
It should be noted that they are very similar to each other. Both use the Bitbucket REST API to update build statuses. Both are very easy to install and configure. On the side of the “native” plug-in from JetBrains there is support for new versions of TeamСity (in TeamCity 10 this plug-in will be built out of the box — an interpreter comment), quick release of new versions and support from a world-famous development team. On the side of TeamCity Stash (Bitbucket) Integration - a little more functionality and detailed instructions for configuring the plugin. The choice of add-on is up to you and depends on your requirements and wishes.