Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Referencing Pull requests for CI server builds (TeamCity)

We would like to build all New/Updated Pull Requests by our CI server (TeamCity). I'm rummaging through search results both from Atlassian and JetBrains but do not seem to get to a straightforward solution.


1. References the use of polling but I can't seem to see any way of directly referencing pull requests in our VCS configuration to trigger automatic builds only on PRs. Otherwise webhooks that need to pass through a 3rd party solution (like Lambda) to translate the webhook call to the right API call towards teamcity.


2. A plugin that used to work on an old version :


3. An article that point blank says you cannot reference PRs, so you have to build all commits (Which I guess doesn't work with PRs coming from Forks)



Hopefully I'm missing something and there's an easy way of achieving this by directly referencing pull requests, otherwise it's either down to Webhooks + 3rd party like Lambda, or fixing that old plugin.


Thanks in advance for any feedback.

3 answers

The fix to Bitbucket Pull Requests Trigger plugin is published as pull request #69 to the main github repository. I downloaded and built the plugin locally, it worked fine with TeamCity 2019.1. 

This is what I am looking for. How do I build the plugin to get the (.zip or other format) so I can upload and install in TeamCity?

If you have Git command line client and Maven installed on your computer, run the following three commands,

    git clone

    cd teamcity-plugins

    mvn package will be located at pullrequests/target directory. Upload and enable it to TeamCity.

Like ashmosaheb likes this

Thanks very much. That helped. I've built the plugin as per the instructions and uploaded the .zip file to TeamCity and all seems to be working so far!

So I ran into the same issue, I think I have something that works without using lambda in the current version of teamcity.

This is for bitbucket cloud, since bitbucket server has a build feature for bitbucket server pull requests

1. Bitbucket pipeline with pull-request keyword. This triggers on pull-request creation or update of pull-request.

bitbucket-pipeline excerpt:

'**': #this runs as default for any branch not elsewhere defined
- step:
name: Trigger Teamcity Build
- make set_build_branch
- make trigger_teamcity

2. The pipeline triggers the teamcity REST api with curl

Makefile excerpt:

curl --header "Content-Type: text/plain" \
--header "Authorization: Bearer $TEAMCITY_ACCESS_TOKEN" \
--header "Origin: [YOUR-URL-HERE]" \
--request PUT \
"[YOUR-URL-HERE]app/rest/projects/id:[YOUR_ROOT_PROJECT]/parameters/trigger_build_branch" \

curl --header "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${TEAMCITY_ACCESS_TOKEN}" \
-H "Origin: [YOUR-URL-HERE]" \
-X POST "[YOUR-URL-HERE]app/rest/vcs-root-instances/commitHookNotification?locator=vcsRoot:(id:[YOUR_VCS_ROOT_ID])"

The first command sets the configuration parameter  trigger_build_branch in the root project which all our other projects inherit parameters from.

The second command triggers a commit hook for the vcs root that the root project uses, which all our projects also use.

3. The VCS root has an active commit hook, but the interval for checking is set to basically never trigger (~ 1 year) so that the only time it is ever triggered is by the curl command

4. The commit hook event then triggers a 'VCS Trigger' with the following parameters

VCS trigger rules: 
Branch filter:

So that it only checks for changes in the  PR branch, develop and master. Although the develop and master filters aren't really necessary.

5. The Build Feature 'Commit Status Publisher' then reports the status of the build back to the bitbucket pull request.

Deric, thank you for this very helpful overview. I did much as you have described and it is working fairly well, except that the build doesn't always trigger, even though my pipeline shows that the commit hook was sent. I'd like for it to build with every commit to the PR, how do you have your VCS root and triggers configured to make this work?

I am working on this same problem right now, and this is my bitbucket pipeline. I send several of the BitBucket built in variables to to TeamCity for use in the build configuration.


image: atlassian/default-image:2

  - step:
     name: Pipeline for Develop and QA Builds
     - echo "Pipeline for Develop and QA builds"

  '**': #runs on all branches not elsewhere defined
 ## Send PR details to a TeamCity build configuration & posts commit hook 
 ##  TeamCity uses these parameters to decorate the PR in BitBucket
 ##  Values are also used when running SonarScanner s

 ## Required Variables 
 ##  TC_URL: full http url to TeamCity server
 ##  TC_TOKEN: REST API access token 
 ##  TC_VCS_ROOT: ID (not the name) of the VCS root
 ##  TC_BUILD_ID: ID (not the name) of the Build configuration
  - step:
     name: Set Parameters on TeamCity Build & send a commit notification
     ## build the header strings for CURL
     - "ORIG=\"Origin: $TC_URL\""                 
     - "AUTH=\"Authorization: Bearer $TC_TOKEN\""
     - "TEXT=\"Content-Type: text/plain\""        
     ## build the path to the TeamCity API to set parameters on the build
     - "SETP=\"--request PUT $TC_URL/app/rest/buildTypes/id:$TC_BUILD_ID/parameters\"" 
     ## push bitbucket pull-request variables to TeamCity build
     - "curl -H \"$ORIG\" -H \"$AUTH\" -H \"$TEXT\" $SETP/BITBUCKET_PR_ID                 --data $BITBUCKET_PR_ID"
     - "curl -H \"$ORIG\" -H \"$AUTH\" -H \"$TEXT\" $SETP/BITBUCKET_BRANCH                --data $BITBUCKET_BRANCH"
     - "curl -H \"$ORIG\" -H \"$AUTH\" -H \"$TEXT\" $SETP/BITBUCKET_COMMIT                --data $BITBUCKET_COMMIT"
     - "curl -H \"$ORIG\" -H \"$AUTH\" -H \"$TEXT\" $SETP/BITBUCKET_REPO_UUID             --data $BITBUCKET_REPO_UUID"
     ## Build the path to the TeamCity api for commit Hook notifications
     - "HOOK=app/rest/vcs-root-instances/commitHookNotification" 
     ## Send a commit notification to the TeamCity VCS root. 
     ## the build must have an appropriate VCS trigger configured
     - "curl -H \"$ORIG\" -H \"$AUTH\" -X POST \"$TC_URL/$HOOK?locator=vcsRoot:(id:$TC_VCS_ROOT)\""

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Bitbucket

New improvements to user management in Bitbucket Cloud 👥

Hey Community! We’re willing to wager that quite a few of you not only use Bitbucket, but administer it too. Our team is excited to share that we’ll be releasing improvements throughout this month of...

3,734 views 10 16
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you