Repository navigation
Fix versionLT misordering a deeper primary-version depth mismatch - #2546
Open
adithya-sn wants to merge 2 commits into
Open
adithya-sn wants to merge 2 commits into
adithya-sn wants to merge 2 commits into
Conversation
Author
|
Pushed a follow-up commit after a closer sanity pass on my own change (this being a core entrypoint script, wanted to double check before leaving it for review):
Wasn't able to get a local PowerShell/Pester run going in my environment (a |
versionLT (and its PowerShell equivalent, Compare-VersionLessThan) decide whether copy_reference_file() should upgrade a bundled plugin already present in JENKINS_HOME. They work by flattening both version strings into one dot-separated sequence (converting '-' to '.') and comparing position by position. That flattening silently misaligns two version strings that have a different number of real dotted version components before their qualifier/build-number, sliding the shorter one's build number into the same comparison slot as the longer one's extra real version component. For apache-httpcomponents-client-5-api's "5.6-191.vb_47e2b_41c698" (installed) vs "5.6.5-209.vd1010d57ee17" (bundled in a newer image): flattened, that's comparing installed's build number "191" directly against image's real third component "5" -- 191 > 5, so the function decided the newer image version was actually older, and copy_reference_file() skipped the upgrade. That left a stale, incompatible apache-httpcomponents-client-5-api installed after a real Jenkins core upgrade, which then failed cloudbees-bitbucket-branch-source's own minimum-version dependency check at boot and cascaded into Blue Ocean's Bitbucket integration failing to load. jenkinsci#2328 already special-cased one specific depth of this same shape mismatch (a 2-part vs. 3-part version split right after the first segment), recognized via a "v"-prefix marker comparison. It doesn't generalize to a mismatch one level deeper, like this one, since it only ever inspects the segment immediately after the first. This replaces that special case with a more general fix: split each version into its real, comparable "primary" dotted version and an optional trailing incremental-build qualifier, stopping before the opaque ".v<hash>" content-hash marker and before any '-' that separates a build number from the primary version. Compare the primaries first, with zero-padding so a depth difference (e.g. "5.6" vs "5.6.5") compares correctly instead of misaligning; only fall back to comparing qualifiers when the primaries are equal. This subsumes the jenkinsci#2328 special case (verified: all of its existing bats/Pester test cases, both forward and reverse direction, plus the pre-existing 1.0/1.1 and major-version-9-vs-10 cases, still pass), so it's removed rather than kept alongside the new logic. Added both directions of the apache-httpcomponents-client-5-api case as new regression tests in tests/functions.bats and tests/functions.Tests.ps1, alongside the existing jenkinsci#1456/jenkinsci#2328 cases.
The previous commit's segment/qualifier comparisons used bare bash arithmetic (\`(( 10#\$sa < 10#\$sb ))\`) and a bare PowerShell \`[int64]\` cast. Real-world Jenkins plugin versions are numeric in every documented test case, but neither implementation is guaranteed that by anything structural, and both would error out (bash) or throw (PowerShell) on a non-numeric segment -- a real regression versus the code being replaced, which only ever used \`sort --version-sort\` (string-based, never fails) and an explicit TryParse-with-string-fallback pattern respectively. Confirmed live: \`versionLT "1.abc" "1.def"\` crashed with "value too great for base" before this change. Since jenkins-support runs under \`set -e\`, this could have aborted the entrypoint outright on an unusual plugin version instead of just comparing it as a string, same as before this whole fix. Added a small segment-level helper (bash: _versionLT_compare_segment; PowerShell: inline TryParse/fallback, mirroring Compare-PluginVersionPrimary's existing pattern) that only does numeric comparison when both sides parse as plain integers, falling back to a plain string comparison otherwise -- restoring the "never fails" property of the code being replaced.
adithya-sn
force-pushed
the
fix/versionlt-primary-depth-mismatch
branch
from
November 23, 2026 16:30
a0221a2 to
4f82e2f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related
#2512 reports and fixes this same underlying bug (same
apache-httpcomponents-client-5-api5.6-191 vs 5.6.x-NNN case), independently, with a narrower patch: it special-cases "both sides have a-and their release parts (before the first-) differ" and compares those release parts only, leaving the rest of the existing flattening/sort logic untouched for every other case.This PR takes a broader approach: it generalizes to a single primary/qualifier split that handles both the with-dash and without-dash shapes uniformly (so it also subsumes #2328's special case, which is removed rather than kept alongside the new logic), rather than adding another special case on top. Flagging the overlap here so maintainers can pick whichever fix they'd rather carry forward -- happy to close this in favor of #2512, or the reverse, whatever's preferred.
Summary
versionLT(and its PowerShell equivalent,Compare-VersionLessThan) decide whethercopy_reference_file()should upgrade a bundled plugin that's already present inJENKINS_HOME. They work by flattening both version strings into one dot-separated sequence (converting-to.) and comparing position by position.That flattening silently misaligns two version strings that have a different number of real dotted version components before their qualifier/build-number, sliding the shorter one's build number into the same comparison slot as the longer one's extra real version component.
Real-world case that surfaced this
apache-httpcomponents-client-5-api's installed version5.6-191.vb_47e2b_41c698vs a newer image's bundled5.6.5-209.vd1010d57ee17. Flattened, that's comparing the installed version's build number191directly against the image version's real third component5—191 > 5, soversionLTdecided the newer image version was actually older, andcopy_reference_file()skipped the upgrade.That left a stale, incompatible
apache-httpcomponents-client-5-apiinstalled after a real Jenkins core upgrade, which then failedcloudbees-bitbucket-branch-source's own minimum-version dependency check at boot (Update required: Apache HttpComponents Client 5.x API Plugin ... to be updated to 5.6.4-204.vfa_29df89ffcf or higher), cascading into Blue Ocean's Bitbucket integration failing to load, and the controller going into a boot-failure restart loop.Why the existing #2328 fix doesn't catch this
#2328 already special-cased one specific depth of this same shape mismatch (a 2-part vs. 3-part version split right after the first segment, recognized via a
v-prefix marker comparison — e.g.3894.vd0f0248b_a_fc4vs3894.3896.vca_2c931e7935). It doesn't generalize: it only ever inspects the segment immediately after the first one, so it doesn't catch a mismatch one level deeper, like this case (5.6vs5.6.5, where the first two segments already match).Fix
Replaces the
v-prefix special case with a more general fix: split each version into its real, comparable "primary" dotted version and an optional trailing incremental-build qualifier, stopping before the opaque.v<hash>content-hash marker and before any-that separates a build number from the primary version. Compare the primaries first, with zero-padding so a depth difference (e.g.5.6vs5.6.5) compares correctly instead of misaligning; only fall back to comparing qualifiers when the primaries are equal.This subsumes the #2328 special case — verified all of its existing bats/Pester test cases, both forward and reverse direction, plus the pre-existing
1.0/1.1and major-version9vs10cases, still pass — so it's removed rather than kept alongside the new logic.Applied the same fix to both the bash (
jenkins-support) and PowerShell (jenkins-support.psm1) implementations, to keep Linux/Windows image parity.Test plan
apache-httpcomponents-client-5-apicase as new regression tests intests/functions.batsandtests/functions.Tests.ps1, alongside the existing Unable to upgrade plugin in Docker Jenkins due to version format #1456/versionLT()injenkins-supportsilently skips plugin upgrades across maintenance-branch and semver+buildnum version bumps #2328 cases.jenkins-supportunder real bash) that all 16 cases pass: the 3 trivial cases, the 4 Unable to upgrade plugin in Docker Jenkins due to version format #1456 real-world cases, the 4versionLT()injenkins-supportsilently skips plugin upgrades across maintenance-branch and semver+buildnum version bumps #2328 forward/reverse cases, the 2 new httpcomponents cases (both directions), and the major-version-9-vs-10 ordering case from the PowerShell test suite.jenkins-support.psm1) port mirrors the bash algorithm exactly; traced it by hand against the same cases (a local PowerShell install wasn't readily available in my environment to run the actual Pester suite, so please let the CI confirm it — happy to adjust if it surfaces anything).🤖 Generated with Claude Code