teamcity.build.branch does not match

I'm using the %teamcity.build.branch% parameter in a Powershell step, but the value reported to the script is not consistent with the branch label created by the branch specification. This problem only occurs sporadically with both triggered builds and manually started builds.

I'm using a git VCS root (for Github), and my default branch is "master" with branch spec set to "+:refs/heads/*"

Any ideas?

8 comments
Comment actions Permalink

Hi Joel,

Could you please provide an example of the incorrectly reported name? What label was set and what was reported in the build script? Please attach screenshots or logs illustrating the issue.

0
Comment actions Permalink

Attached are some screenshots of what I'm seeing.

- The build parameters report teamcity.build.branch = "dev" (Capture.png)
- The "Branch" value on the build reports "master-zd-13247" (Capture2.png)
- When I call Write-Host "%teamcity.build.branch%" from inside my powershell script it reports "dev" (Capture3.png)

I should add that these two branches are for example. It can happen with any combination of branch names, including master, and even branches that no longer exist.



Attachment(s):
Capture3.PNG
Capture2.PNG
Capture.PNG
0
Comment actions Permalink

What TeamCity version is used?
Do you have any dependencies configured in this build configuration?
Please reproduce the issue and attach teamcity-vcs and teamcity-server.log files.

0
Comment actions Permalink

I'm on 9.1.3 (build 37176).
I have no dependencies.

Attached are the logs. One of the builds which had this problem occurred at 12:58. You can see it start on line 48 of teamcity-vcs.log. The vcs log clearly shows that the update was pulled from "refs/heads/master-zd11657", but the build parameters show "master-zd-13134".



Attachment(s):
teamcity-server.log.zip
teamcity-vcs.log.zip
0
Comment actions Permalink

Hi Joel,

do you use parameters in VCS root settings? Is VCS trigger the only trigger in the build configuration? Does this problem happen to one configuration only or other are also affected?

0
Comment actions Permalink

I use user defined parameters in the VCS root:

- Fetch URL: https://github.com/org/%Repo%.git
- Default Branch: %Branch%

The VCS trigger is my only trigger.

I only see it happening on one configuration.

0
Comment actions Permalink

I cannot reproduce it so far, in my case the teamcity.build.branch parameter is always reflect the branch shown in UI. The parameters are defined in a build configuration, right? Do you have any 3rdparty plugins installed? Do you use teamcity service messages? If so, please check if the change branch parameters on the agent. Does the build always get a wrong branch, or sometimes it gets the right one? Is there anything special about builds with the wrong branch?

0
Comment actions Permalink

The parameters are defined in the project.
I have no third party plugins.
I don't use service messages.
Sometimes the build get's the right branch. I don't see any pattern though. Both the default branch and other branches will sometimes be right and sometimes wrong.

At this point I've created a new configuation (all the same settings and steps) and it seems to be working as expected. I've disabled all the steps on the old configuation except the powershell script which logs the parameter.

0

Please sign in to leave a comment.