Reputation: 61
Using TeamCity 2020.2.4
Build job has multiple VCS Root set up comprised of "source code" and "utility scripts".
The "utility scripts" are always on same branch (master); however, the "source code" is either in master (aka: default) or release/### branch.
The "source code" root has:
Default branch: refs/heads/master
Branch specification:
+:refs/heads/(master)
+:refs/heads/(release/*)
Currently there are 2 builds, one for master (longer running builds), and one for release (does bunch of extra steps to prep for release).
Initially there was a desire to just hide the "master" default branch from displayed, thus followed TeamCity's own docs (https://www.jetbrains.com/help/teamcity/branch-filter.html#Branch+Filter+Format) that imply I can tweak Branch Filter:
+:*
-:<default>
(also some SO articles that mention this as an answer, but years old)
However when doing so, end up getting error:
Failed to collect changes, error: Builds in default branch are disabled in build configuration
Looks like triggers run just fine, but it's the Manual build where things really go sideways.
Have tried even overriding with teamcity.build.branch
with a default + prompt parameter, no such luck.
Have seen circumstances where wrap it in another job, but that's bit hacky just to do what TC says should be possible directly.
Upvotes: 2
Views: 3636
Reputation: 1
I get the same behavior in TeamCity v2023.11.4.
The Branch Filter field must include the full git path rather than just the logical branch name:
If you have this Branch Specification in the VCS Root:
+:refs/heads/(mybranch)
Then you must have this Branch Filter in the Version Control Settings of your Build Config:
+:mybranch
+:refs/heads/mybranch
And if the branch you want to build is like this:
josh/mybranch
And you want TeamCity to show "mybranch" instead of "josh/mybranch"
then you need this Branch Specification:
+:refs/heads/josh/(mybranch)
and this Branch Filter (yes, both of them):
+:mybranch
+:refs/heads/josh/mybranch
Upvotes: 0
Reputation: 61
Found a solution, posting here to help the next person ...
So, despite TeamCity mentioning "logical branch name" for the "Branch Filter" in Version Control Settings, can actually provide full branch name.
Thus "refs/heads/master" can be used. This effectively seems to allow one of the VCS roots to continue using it's default/master, while allowing other options for the 2nd root.
For example:
VCS Root #1 config:
Default: refs/heads/master
Spec:
+:refs/heads/(master)
+:refs/heads/(release/*)
VCS Root #1 config:
Default: refs/heads/master
Spec: (empty)
And when doing different jobs, the Branch Filter would be set as such:
"master only":
+:refs/heads/master
+:release/*
-:master
"releases only":
+:refs/heads/master
+:<default>
+:master
Worth noting, despite that even though "master" is default, still need to actually specify both ... at first pass might not seem intuitive, but it is what it is - and it works.
Upvotes: 4