当前位置: 动力学知识库 > 问答 > 编程问答 >

continuous integration - 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.

网友答案:

See: http://blog.jetbrains.com/teamcity/2013/02/automatically-building-pull-requests-from-github-with-teamcity/

The gist is that you can add a Branch Specification, +:refs/pull/*/merge, to the project's VCS Root. This will cause the trigger a build on the merged output of the pull request.

网友答案:

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.

网友答案:

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.

网友答案:

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)

分享给朋友:
您可能感兴趣的文章:
随机阅读: