Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-63088

The logic to trigger builds based on buildStrategies seems wrong

    XMLWordPrintable

Details

    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

      Attachments

        Activity

          rduval R. Duval created issue -
          rduval R. Duval made changes -
          Field Original Value New Value
          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`. 
          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}}. 
          sookad Hans Koster added a comment - - edited

          We experience the same. We initially used two strategies:

           Ignore committer strategy

           Skip initial build on first branch indexing

          Because Jenkins commits some changes in my job, the job is rebuilt endlessly. When I remove the Skip initial build strategy, the Ignore committer strategy works as intended and the build is not rebuilt endlessly.

          rduval, thanks for this Jira issue. It saves my day !

          Environment: Jenkins 2.204.5, branch-api 2.5.5.

          sookad Hans Koster added a comment - - edited We experience the same. We initially used two strategies:  Ignore committer strategy  Skip initial build on first branch indexing Because Jenkins commits some changes in my job, the job is rebuilt endlessly. When I remove the Skip initial build strategy , the  Ignore committer strategy works as intended and the build is not rebuilt endlessly. rduval , thanks for this Jira issue. It saves my day ! Environment: Jenkins 2.204.5, branch-api 2.5.5.
          jsloth Jakob Sloth Nielsen made changes -
          Attachment image-2021-11-18-10-32-09-647.png [ 56789 ]

          People

            Unassigned Unassigned
            rduval R. Duval
            Votes:
            2 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated: