Repository navigation
feat(sdk): detect PR context on Jenkins multibranch builds (#234) - #238
Merged
Merged
Conversation
Jenkins Branch Source PR builds now carry a PullRequestContext for github.com, gitlab.com and Azure DevOps Services repositories, parsed from CHANGE_URL. The PR head commit is read from refs/remotes/origin/$BRANCH_NAME and used only when it is GIT_COMMIT (head strategy, fast-forward) or GIT_COMMIT's first parent (merge strategy), so a ref that moved past the built commit yields no context. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
... and 1 file with indirect coverage changes 🚀 New features to boost your workflow:
|
git merge runs gc --auto, so on a long-lived workspace the merge commit Jenkins just made can end up in a pack the reader doesn't parse. Fall back to `git rev-parse <sha>^1` when the commit isn't a loose object. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
#234) A background gc --auto can pack refs and delete the loose PR ref between the existence check and the read. Catch the IOException and fall through to packed-refs, which pack-refs writes before deleting loose refs. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Covers malformed refs, packed-refs and loose objects, the git fallback's timeout and bad output, and unsupported CHANGE_URL shapes. Reading a loose object no longer checks File.Exists first, so a gc pruning it mid-read falls back to git instead of returning null. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
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.
Closes #234.
Jenkins Branch Source PR builds now carry a
PullRequestContext.How the PR head commit is found
No Jenkins env var holds the PR head under the merge strategy (the default). Jenkins checks out the PR head and merges the target into it, so:
refs/remotes/origin/$BRANCH_NAMEfrom$WORKSPACE/.git(loose ref, thenpacked-refs).GIT_COMMIT(head strategy, or the merge fast-forwarded) orGIT_COMMIT's first parent (merge strategy).null. For example, the ref moved past the built commit, or.gitis a file.Changes
JenkinsPullRequestDetector: gated onCHANGE_ID. Platform, owner and name come fromCHANGE_URL: github.com, gitlab.com (nested groups), and Azure DevOps Services (dev.azure.comand*.visualstudio.com). Owner/name match the Azure Pipelines and GitLab detectors. If the PR number in the URL ≠CHANGE_ID, it returnsnull.GitRepositoryReader: minimal read-only.gitaccess. It reads refs and the first parent of a loose commit (zlib viaDeflateStream). There's no pack parsing: a commit packed bygit gc --auto(long-lived workspaces) falls back togit rev-parse <sha>^1with a 5 s timeout, and returnsnullwithoutgitonPATH. It validates ref names and SHAs before building file paths.EnvironmentDetector:CI.IsPullRequestuses the sharedIsPullRequestBuildpredicate. GHPRB is still flagged.AddXpingPullRequest.configuration-reference.mdand the Jenkins section and commit table ofci-cd-setup.md.Tests
JenkinsPullRequestDetectorTests:CHANGE_ID, URL/ID mismatch, each required variable missingGitRepositoryReaderTests: run against real repos built with thegitCLI in a temp dir. They cover loose and packed refs, a--no-ffmerge's first parent, root and packed objects, a worktree.gitfile, and unsafe inputs.Not verified
Not yet run on a real Jenkins. If
GIT_COMMITor thePR-n/MR-nref names differ from what the plugin source shows, the detector returnsnullrather than a wrong commit.🤖 Generated with Claude Code