Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run CI build on pull request merge in TeamCity

Tags:

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.

like image 556
JonSquared Avatar asked Aug 12 '14 13:08

JonSquared


People also ask

Is a pull request the same as a merge?

A Git pull request is essentially the same as a Git merge request. Both requests achieve the same result: merging a developer's branch with the project's master or main branch. Their difference lies in which site they are used; GitHub uses the Git pull request, and GitLab uses the Git merge request.

How do I merge a pull request after approval?

Once you are ready to merge a pull request, and when the reviewers have approved it, click Merge at the top right of the pull request view. You can merge a pull request if you have write (or admin) permission on the project.

How does TeamCity work with GitHub?

When the new pull request is created, we can choose the branch in the target repository. This is the branch we can filter in the Pull Requests build feature settings in TeamCity. Once the pull request is submitted, TeamCity will detect that there's a new branch in the GitHub repository and will start the build.


2 Answers

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.

like image 68
John Hoerr Avatar answered Sep 18 '22 11:09

John Hoerr


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.

like image 33
BeeTee2 Avatar answered Sep 21 '22 11:09

BeeTee2