0
votes

We have a dedicated vcs root which we use to check in steps that check branches (which is a subset of the stuff we do for code in master)

I tried to filter the bitbucket pull request branches and the master branch to have it only trigger on "real" branches, but it still keeps building master commits as well, which is a waste of resources.

I tried this spec:

-:<default>
-:refs/pull-requests/*
+:*

According to my understanding of the spec syntax this should work, but teamcity disagrees.

1

1 Answers

3
votes

There are 3 places to define branches. The first 2 (Default Branch and Branch Specification) are in your VCS Root, use the Git specification format (refs/heads/master), and define what refs to monitor for changes [1].

VCS Root

Team City requires a Default Branch to which changes are compared. This is generally master unless you have a non-standard configuration. In Branch Specifications, you need to define any additional refs to monitor for changes. Any changes to refs defined in Branch Specification hooks into TeamCity for processing.

VCS Root settings for your scenario:

  • Default Branch: /refs/heads/master
  • Branch Specification: +:*

Version Control Settings

The magic truly happens in the Version Control Settings. In these settings, only the defined branches are made available to the build. This section uses the logical name to define which branches to include. You may need to click on "Show Advanced Settings" to see the Branch Filter [2].

You can test everything is working correctly by using the wizard to the right of Branch Filter. Clicking the little wand icon, you should see all of the branches that the VCS Root is monitoring. It should include and any other branches currently in your git repository. You can use the Wizard to build your filter if this is easier for you.

For your scenario, you should monitor everything (+:*), exclude the master branch (-:<default>), and any other branches you wish to ignore (-:pull-requests/*). It should look something like:

+:*
-:<default>
-:pull-requests/*

This means that any changes that occur in master or any branch that starts with pull-requests are ignored.

You could more finely control what happens based on branches from here using the Build Triggers and specifying which specific branches trigger a build. [3]

Notes: There are some rules regarding Branch Filtering and Specification that may be of interest.[4]

References:

1: https://www.jetbrains.com/help/teamcity/2019.2/working-with-feature-branches.html#WorkingwithFeatureBranches-Configuringbranches

2: https://www.jetbrains.com/help/teamcity/2019.2/branch-filter.html

3: https://www.jetbrains.com/help/teamcity/2019.2/configuring-build-triggers.html

4: https://www.jetbrains.com/help/teamcity/2019.2/working-with-feature-branches.html#WorkingwithFeatureBranches-branchSpec