Symptoms
A build configuration monitors pull request or feature branches with a VCS trigger, and the default branch is excluded from triggering so that builds run on pull requests only. A typical setup uses the Pull Requests build feature (or a refs/pull/* branch specification), a VCS trigger branch filter such as +:* combined with -:<default>, and checkout rules that limit the configuration to one directory of a monorepo.
A build is triggered on every open pull request whenever a single commit is pushed to the default branch, including pull requests that do not change any file the configuration watches.
Cause
TeamCity calculates the changes for a branch as the changes from the branch's revision to the previous build in that branch or to a build in the default branch. By default, the pending changes shown for a feature branch also include the default branch's changes, up until the default branch is built. See Working with Feature Branches and Configuring VCS Settings.
When the default branch is never built, for example because it is excluded from the trigger and appears under Non-built Branches, each new commit on the default branch keeps appearing as a pending change on every monitored feature or pull request branch. A VCS trigger whose branch filter matches those branches (for example +:*) then starts a build for each one, including pull requests that changed nothing under the configuration's checkout scope.
This behavior does not depend on whether pull requests are tracked as merge refs (refs/pull/*/merge) or head refs (the Pull Requests build feature). It is caused by the default branch not having a build to act as the baseline for change calculation.
Resolution
Recommended fix: exclude default-branch changes from other branches
Enable Exclude default branch changes from other branches in the build configuration's Version Control Settings, under Changes Calculation Settings. With this enabled, a feature or pull request branch shows and triggers on its own changes only, so a commit on the default branch no longer appears as a pending change on the other branches. See Configuring VCS Settings.
When the affected configurations are derived from a template, set the option on the template so that all configurations inherit it. Enabling it on one configuration and confirming that the unrelated pull request builds stop is recommended before applying it more widely.
Alternative: build the default branch
Allowing the default branch to build establishes the baseline that TeamCity uses for change calculation. Once a build exists on the default branch, its changes no longer appear as pending on other branches. This requires running the configuration on the default branch, which may be undesirable for a configuration intended to build pull requests only.
Comments
0 comments
Please sign in to leave a comment.