First, you need to upgrade to a newer version of TeamCity, there are a lot of security vulnerabilities that have been patched since the version you list, and secondly, each source code repository handles PRs differently, so you need a relatively recent build that matches how your repo works.
Use the Pull Requests build feature and specify which branches are targets of your PRs. If you only want to pull PRs that target master, the target branch specification would be:
+:refs/heads/master
(or however your repo organizes it)
If you can't use the Pull Requests Build Feature for some reason, another alternative is to trigger a build using the REST API of TeamCity and a "commit hook". When you make the API call, you will have to provide all parameters that your build needs to run, like the branch name. We used to do our PR builds this way before the Pull Requests build feature supported Bitbucket, and I have included our yaml pipeline for reference. Every variable that starts "BITBUCKET_" is a TeamCity build parameter used by our build configuration. The pipeline sets these parameters and then publishes the commit hook to trigger the build. The only parameter you'd have to specify is the branch you want to build; we included others for our analysis tools.
image: atlassian/default-image:2
pipelines:
branches:
'{develop,qa}':
- step:
name: Pipeline for Develop and QA Builds
script:
- echo "Pipeline for Develop and QA builds, no commit hook"
pull-requests:
'**': #runs on all branches not elsewhere defined
##
## Send PR details to a TeamCity build configuration & posts a commit hook notification
## TeamCity uses these parameters to decorate the PR in BitBucket with build status (see "Commit status publisher")
##
## Required Variables
## TC_URL: full http url to TeamCity server
## TC_TOKEN: REST API access token (generated through the TeamCity administrator page)
## TC_VCS_ROOT: ID (not the name) of the VCS root to post a commit notification to
## TC_BUILD_ID: ID (not the name) of the Build configuration to pass parameters to
##
- step:
name: Set Parameters on TeamCity Build & send a commit notification to the VCS
script:
## build the header strings for CURL
- "ORIG=\"Origin: $TC_URL\"" # Set origin to TeamCity url
- "AUTH=\"Authorization: Bearer $TC_TOKEN\"" # TeamCity auth token to invoke the REST api
- "TEXT=\"Content-Type: text/plain\"" # Plaintext requests used for setting build parameters
## 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_PR_DESTINATION_BRANCH --data $BITBUCKET_PR_DESTINATION_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"
- "curl -H \"$ORIG\" -H \"$AUTH\" -H \"$TEXT\" $SETP/BITBUCKET_REPO_OWNER_UUID --data $BITBUCKET_REPO_OWNER_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. for the notification to
## trigger a build, 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)\""
If you opt for this route, be sure to very carefully configure the permissions on the tokens you create.