JonSquared
JonSquared

Reputation: 683

Run CI build on pull request merge in TeamCity

I have a CI build that is setup in TeamCity that will trigger when a pull request is made in BitBucket (git). It currently builds against the source branch of the pull request but it would be more meaningful if it could build the merged pull request.

My research has left me with the following possible solutions:

  1. Script run as part of build - rather not do it this way if possible
  2. Server/agent plugin - not found enough documentation to figure out if this is possible

Has anyone done this before in TeamCity or have suggestions on how I can achieve it?

Update: (based on John Hoerr answer)

Alternate solution - forget about TeamCity doing the merge, use BitBucket web hooks to create a merged branch like github does and follow John Hoerr's answer.

Upvotes: 21

Views: 9975

Answers (4)

John Hoerr
John Hoerr

Reputation: 8035

Add a Branch Specification refs/pull-requests/*/merge to the project's VCS Root. This will cause TeamCity to monitor merged output of pull requests for the default branch.

Upvotes: 10

meriouma
meriouma

Reputation: 121

You can also use this plugin : https://github.com/ArcBees/teamcity-plugins/wiki/Configuring-Bitbucket-Pull-Requests-Plugin

(Full disclosure : I'm the main contributor :P, and I use it every day)

Upvotes: 1

Adam Adamaszek
Adam Adamaszek

Reputation: 4054

Seems that BitBucket/Stash creates branches for pull requests under:

refs/pull-requests//from

You should be able to setup a remote run for that location, either by the Teamcity run-from-branch feature, or by a http post receive hook in BitBucket/Stash.

Upvotes: 3

BeeTee2
BeeTee2

Reputation: 777

It sounds to me like the functionality you're looking for is provided via the 'Remote Run' feature of TeamCity. This is basically a personal build with the merged sources and the target merge branch.

https://confluence.jetbrains.com/display/TCD8/Branch+Remote+Run+Trigger

"These branches are regular version control branches and TeamCity does not manage them (i.e. if you no longer need the branch you would need to delete the branch using regular version control means).

By default TeamCity triggers a personal build for the user detected in the last commit of the branch. You might also specify TeamCity user in the name of the branch. To do that use a placeholder TEAMCITY_USERNAME in the pattern and your TeamCity username in the name of the branch, for example pattern remote-run/TEAMCITY_USERNAME/* will match a branch remote-run/joe/my_feature and start a personal build for the TeamCity user joe (if such user exists)."

Then setup a custom "Pull Request Created" Webhook in Bitbucket.

https://confluence.atlassian.com/display/BITBUCKET/Tutorial%3A+Create+and+Trigger+a+Webhook

So for your particular use case with BitBucket integration, you could utilize the WebHook you create, and then have a shell / bash script (depending on your TeamCity Server OS) that runs the remote run git commands automatically, which will in turn automatically trigger the TeamCity Remote Run CI build on your server. You'll then be able to go to the TeamCity UI, +HEAD:remote-run/my_feature branch, and view the Remote Run results on a per-feature basis, and be confident in the build results of the code you merge to your main line of code.

Upvotes: 3

Related Questions