jenkinsci / jenkinsci/branch-api-plugin

[JENKINS-63088] The logic to trigger builds based on buildStrategies seems wrong

Open
#746 2 comments 0 reactions 0 assignees View on GitHub
component:branch-api-plugin imported-jira-issue priority:minor resolution:unresolved
Dominant language
Java
Stars
39
Forks
154
PR merge metrics
No merged PRs in 30d

Description

After digging through the source code of the Branch API plugin I came across the following logic to evaluate the triggering of automatic builds based on Build Strategies, https://github.com/jenkinsci/branch-api-plugin/blob/master/src/main/java/jenkins/branch/MultiBranchProject.java#L2246-L2257

Apparently this logic will trigger a branch build with a short-circuit OR, meaning if I have two strategies returning false and one returning true the branch build will be triggered no matter what.

A clear example of the situation above and the problems it brings is the use of the strategy jenkins.branch.buildstrategies.basic.SkipInitialBuildOnFirstBranchIndexing. After the first build, it will always return true, which in turn will make all other strategies, like jenkins.branch.buildstrategies.basic.ChangeRequestBuildStrategyImpl useless, even if it returns false

---
Originally reported by rduval, imported from: The logic to trigger builds based on buildStrategies seems wrong


  • status: Open
  • priority: Minor
  • component(s): branch-api-plugin
  • label(s): configuration, plugins
  • resolution: Unresolved
  • votes: 2
  • watchers: 4
  • imported: 20251211-141027

Raw content of original issue

After digging through the source code of the Branch API plugin I came across the following logic to evaluate the triggering of automatic builds based on Build Strategies, https://github.com/jenkinsci/branch-api-plugin/blob/master/src/main/java/jenkins/branch/MultiBranchProject.java#L2246-L2257

Apparently this logic will trigger a branch build with a short-circuit OR, meaning if I have two strategies returning false and one returning true the branch build will be triggered no matter what.

A clear example of the situation above and the problems it brings is the use of the strategy jenkins.branch.buildstrategies.basic.SkipInitialBuildOnFirstBranchIndexing. After the first build, it will always return true, which in turn will make all other strategies, like jenkins.branch.buildstrategies.basic.ChangeRequestBuildStrategyImpl useless, even if it returns false

  • environment: Docker 19.03.6-ce, OpenJDK 11.0.7, Jenkins 2.235.1, branch-api 2.5.6

1 attachment

- [image-2021-11-18-10-32-09-647.png](https://issues.jenkins.io/secure/attachment/56789/image-2021-11-18-10-32-09-647.png)
> ![image-2021-11-18-10-32-09-647.png](https://issues.jenkins.io/secure/attachment/56789/image-2021-11-18-10-32-09-647.png)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.