Repository navigation
Conversation
…matching branches Every build copies the previous build's buildsByBranchName, so a job that builds a different branch on each run (for example a parameterized branch specifier for merge requests) stores one entry per branch it ever built in every build.xml. On a job with ~3700 retained builds this reached 2.9 MB per build and made the GitLab plugin's already-built lookup take minutes per webhook. The new opt-in extension (and multibranch trait), limitBuildsByBranchHistory, drops entries whose branch matches none of the branch specifiers right after the history is copied. lastBuild is kept, so BuildData consumers that match on it are unaffected, and the default behaviour does not change. Only the default and ancestry build choosers are affected; other choosers keep the full history.
|
Hi @MarkEWaite, Can you review this PR when you have time?
Questions:
Thank you. |
There are many places requesting my time right now. The git plugin is lower on my priority list than Jenkins core and Jenkins core is taking all the time that I have available.
Yes, that is a great direction. It moves the workaround into a user accessible feature that they can choose to enable when the problem occurs, especially in cases like yours where they know the problem will occur.
Label has been added
Yes, a screenshot needs to be included in the documentation so that it is easier for readers to find the option and understand it in context. You can use the incremental build of the pull request from the "Jenkins Incremental Publisher" page on the checks page. That allows you to immediately benefit from the change and allows others to use the change as well. |
|
Thank you for the answers and the label.
|
Fixes the growth described in JENKINS-19022 (#2308) for jobs that build one branch per build, without changing behaviour for anyone who does not enable it.
Every build copies the previous build's
buildsByBranchName. A job that builds a different branch on each run, for example a parameterized branch specifier for merge requests, therefore stores one entry for every branch it ever built in everybuild.xml.On one of our jobs (about 3700 retained builds, up to 1680 entries per map) each
build.xmlreached 2.9 MB. The GitLab plugin's already-built lookup loads every retained build, and it took about 6 minutes per merge request webhook. Clearing the map with the script from the README fixed it, which is what led to this change.This adds an opt-in extension,
limitBuildsByBranchHistory(), and a matching multibranch trait. Right afterGitSCMcopies the previous build'sBuildData, the extension removes the entries whose branch matches none of the job's branch specifiers. The key is tried in the forms the build chooser accepts (origin/x,refs/remotes/origin/x,remotes/origin/x,x,refs/heads/x).Compatibility, given why #578 was reverted (#689):
BuildDataaction is still added to every build. Its class, fields, serialization andlastBuildare unchanged, so plugins that read it keep working.GitSCM._checkoutthat runs only when the extension is configured. Without the extension nothing changes.Trade-off when enabled, documented in the help and README. With a parameterized specifier the history of other branches is dropped, so:
GIT_PREVIOUS_COMMITandGIT_PREVIOUS_SUCCESSFUL_COMMITof a branch start fresh when it is built again after other branches;Wildcard specifiers keep every matching entry, so the option does not reduce their history. Their polling is unaffected.
This follows the opt-in direction of #568, which was closed by its author in favour of #578. Unlike #568, it keeps the entries that still match the branch specifiers, so wildcard jobs keep their already-built detection.
Testing done
mvn clean verify: 5290 tests, 0 failures, SpotBugs 0.New tests in
LimitBuildsByBranchHistoryTestandLimitBuildsByBranchHistoryPipelineTest:build.xmlstays flat;checkout scmGit(...)run.Side-by-side Jenkins 2.580.2 runs comparing released 5.11.0 with this branch, option off. Installed plugins: workflow-aggregator, gitlab-plugin 1.2162, git-parameter, git-tag-message 1.7.1, github 1.47, blueocean-autofavorite. Over 50 builds and 25 polls, the following were identical:
BuildDatainbuild.xml, theapi/jsongit fields, theGIT_*variables, changelogs, and polling decisions.Option on: these return the same results as with the option off:
BuildUtillookups by SHA and by branch;BuildDataHelper;lastBuiltRevisioninapi/json(JENKINS-55939);/git/page.Not exercised: gitlab-plugin
CommitStatusUpdater(needs a live GitLab), and blueocean-autofavorite (it only acts on multibranch jobs).Scale test: two Pipeline jobs, each with two checkouts, built across 300 branches.
build.xmlbuildsByBranchNamesize@since TODOis left for the maintainer to set.Submitter checklist