jenkinsci / jenkinsci/branch-api-plugin

[JENKINS-67725] Need to be able to customize BranchBuildStrategies to not build in the future. Not just a one time evaluataion.

Open
#766 3 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

The use case:



  • Imagine I want to have an ephemeral Jenkins (Docker/K8S/etc).

  • I want it to be preconfigured with multibranch pipelines and/or Github/Bitbucket organization folders.

  • I want it to come online and when it does, it will scan for unknown repositories and branches and cause a build storm.

 


 

I think the requirements are relatively simple and so is the implementation:



  • Here is where all branches come in the front door

  • It will always hit `observeNew` first.

    • We can use a BuildStrategy to not run any build that has a commit older than some EPOCH time.



  • The next time a webhook/index comes in it hits `observeExisting`

    • Most times I notice it hits

      • if (changesDetected(revision, project, scmLastBuiltRevision)) {



    • changesDetected only evaluates last built revision. Problem 1

    • And it always hits lastSeenRevisionOrDefault which saves last seen revision

    • _factory.setLastSeenRevisionHash(project, scmLastBuiltRevision);



  • So we should be able to do this in a 2 step process.

    1. Add build strategy that refuses to build if commit ID is not after a starting time (easily programmed on jenkins master startup)

    2. Have the branch-api-plugin have an option to save lastseenrevision as lastbuilt revision.



 

#1 - Is a little harder since we are not handed any kind of probe so we have to hit Github right now (API) (More unnecessary API calls).  But it does stop the build.  In #2 I added SCMEvent as an extension of BuildBranchStrategy that allows us to see time of commit to help make less API calls to github.

#2 - A literal property/config item - copy/boolean for when lastSeenRevisionOrDefault is called - also call  setRevisionHash on the same factory.  So if we have seen it (assume built).  (Is there anything wrong with this design?). Feature Flag?  Another option is to impact how `changesDetected` works or make it extendable.


 

I will start on #1

---
Originally reported by carpnick2, imported from: Need to be able to customize BranchBuildStrategies to not build in the future. Not just a one time evaluataion.


  • status: Open
  • priority: Minor
  • component(s): branch-api-plugin
  • resolution: Unresolved
  • votes: 0
  • watchers: 2
  • imported: 20251211-141027

Raw content of original issue

The use case:



  • Imagine I want to have an ephemeral Jenkins (Docker/K8S/etc).

  • I want it to be preconfigured with multibranch pipelines and/or Github/Bitbucket organization folders.

  • I want it to come online and when it does, it will scan for unknown repositories and branches and cause a build storm.

 


 

I think the requirements are relatively simple and so is the implementation:



  • Here is where all branches come in the front door

  • It will always hit `observeNew` first.

    • We can use a BuildStrategy to not run any build that has a commit older than some EPOCH time.



  • The next time a webhook/index comes in it hits `observeExisting`

    • Most times I notice it hits

      • if (changesDetected(revision, project, scmLastBuiltRevision)) {



    • changesDetected only evaluates last built revision. Problem 1

    • And it always hits lastSeenRevisionOrDefault which saves last seen revision

    • _factory.setLastSeenRevisionHash(project, scmLastBuiltRevision);



  • So we should be able to do this in a 2 step process.

    1. Add build strategy that refuses to build if commit ID is not after a starting time (easily programmed on jenkins master startup)

    2. Have the branch-api-plugin have an option to save lastseenrevision as lastbuilt revision.



 

#1 - Is a little harder since we are not handed any kind of probe so we have to hit Github right now (API) (More unnecessary API calls).  But it does stop the build.  In #2 I added SCMEvent as an extension of BuildBranchStrategy that allows us to see time of commit to help make less API calls to github.

#2 - A literal property/config item - copy/boolean for when lastSeenRevisionOrDefault is called - also call  setRevisionHash on the same factory.  So if we have seen it (assume built).  (Is there anything wrong with this design?). Feature Flag?  Another option is to impact how `changesDetected` works or make it extendable.


 

I will start on #1

Contributor guide

Open the contributing guide

Research direction

Start with MultiBranchProject.java at the linked entry point, then trace observeNew, observeExisting, changesDetected, and lastSeenRevisionOrDefault. Review the referenced branch build strategy and PR 291 before choosing an approach. Done means the configured strategy prevents unwanted historical builds across later indexing or webhook events, with tests covering the behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend, devtools
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.