Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I override the <default> branch name in TeamCity 7.1 using Git branching support?

I've got a CI build pulling feature branches from Github and building/packaging them into a local folder, using a folder naming convention based on the project, branch and build number.

For named branches (feature1, feature2) this is working great.

The problem is that when I do a commit to the master, TeamCity exposes teamcity.build.branch as <default> - which means when the build step expands

E:\Packages\MyProject\%teamcity.build.branch%\

it's ending up with E:\Packages\MyProject\<default> - which is then crashing the build step because it isn't a valid Windows path.

I can see the master branch name in the fully-qualified build parameter:

teamcity.build.branch                         <default>
teamcity.build.checkoutDir                    C:\TeamCity\BuildAgents\agent-mulder\work\2151838a7933464d
teamcity.build.default.checkoutDir            2151838a7933464d
teamcity.build.id                             16347
teamcity.build.vcs.branch.github_myproject    refs/heads/master

but ideally I need to get master as the teamcity.build.branch for use in my build steps.

Can I transform the parameter at runtime? Override the behaviour? I've even tried setting the VCS branch name to DO_NOT_USE in the hope that "master" would no longer match the default - but this doesn't appear to work either.

like image 615
Dylan Beattie Avatar asked Aug 30 '12 11:08

Dylan Beattie


People also ask

How do I change the default branch in git?

Select your Git repository. Your branches are displayed under your repo. Select the ... next to the branch you want to set as default, then select Set as default branch.


3 Answers

In teamcity 7 its simply %vcsroot.branch% that returns develop.

In my case I have

%MajorVersion%.%MinorVersion%.%PatchVersion%-%vcsroot.branch%

Which are all set in build parameters. The number format is %BuildFormatSemVer% which is the stuff above and . {0}

%BuildFormatSemVer%.{0}

Which returns

#1.0.0-develop.4
like image 62
Chris McKee Avatar answered Sep 17 '22 11:09

Chris McKee


Not ideal, but I was able to work around it by creating a new branch in git named "teamcity" and setting that as the default branch in TeamCity, it seems to require that the branch actually exist, since it worked when I created the branch, but didn't when you just entered a fake name.

Hopefully they actually fix this, because this is definitely a hack.

like image 39
markus101 Avatar answered Sep 19 '22 11:09

markus101


We have run into this problem several times when creating pipelines. It is the most visible when trying to automatically build feature and release branches using the Gitflow workflow. What we've been able to do was to use teamcity.build.vcs.branch.github_myproject and a regular expression in sed to sanitize the string whenever we wish to use it. This is mainly to watermark artifacts for debugging purposes.

The larger issue, at least for us, is that the TeamCity 7.1.1 version does not automatically fire off dependency builds for anything that isn't the default build in the VCS root. Obviously this is a huge pain point as we're now going to have to click manually in the tool. We haven't yet figured out a clean way to get around this other than hooks in git which use the HTTP API to call out to the proper build step.

like image 30
John Bellone Avatar answered Sep 18 '22 11:09

John Bellone