Ömer Faruk Aplak
Ömer Faruk Aplak

Reputation: 911

Git pull request branch name in teamcity


I configured git pull requests my teamcity server for QA testing environment. If I use TeamCity feature branching integration, I can get branch name with this property: %teamcity.build.branch%.

When use pull request, the %teamcity.build.branch% property return pull request number (1,2,3 etc).

How can I get pull request branch name?

Upvotes: 9

Views: 5601

Answers (2)

conny
conny

Reputation: 10145

I'm not sure that anything akin to SYSTEM_PULLREQUEST_SOURCEBRANCH is available in TeamCity, but perhaps you can make use of the "logical branch name" instead? In TC, this directly corresponds to the substring matched by the * placeholder that you probably have added in your VCS Root -> Branch Specification.

Caveat: some articles advice you to have an extra Branch Spec. like +:refs/pull/*/head and +:refs/pull/*/merge. The effect of that is: if "42" happens to be the Pull Request id, the full ref name will be refs/pull/42/head and thus TeamCity will match and show only 42 as the (logical) branch name for both the merging branch and builds of the merge result.

One workaround to this is to make the asterisk match a long-enough substring of the (PR) ref name to be meaningful to you. Another is to use brackets to include more of the ref. Your requirements will depend a bit on your branch naming conventions.

Example:

Default branch:

refs/heads/develop

Branch Specification:

+:refs/(pull/*/merge)
+:refs/heads/*

...will show branches like pull/42/merge, master, hotfix/1.2.3 etc.

Upvotes: 1

Pavel Sher
Pavel Sher

Reputation: 2211

Parameter teamcity.build.branch is a logical branch, i.e. it's a part of a branch from your branch specification matched by *.

There is another parameter teamcity.build.vcs.branch.<VCS root ID> which contains full Git branch name. Seems this is what you need.

You can read more on this in documentation: http://confluence.jetbrains.com/display/TCD8/Predefined+Build+Parameters#PredefinedBuildParameters-BranchRelatedParameters

Upvotes: 7

Related Questions