Troubles with local shallow clone as an origin repository#3988
Open
jimklimov wants to merge 1 commit into
Open
Troubles with local shallow clone as an origin repository#3988jimklimov wants to merge 1 commit into
jimklimov wants to merge 1 commit into
Conversation
… repository Signed-off-by: Evgeny Klimov <klimov@provys.com>
This comment was marked as off-topic.
This comment was marked as off-topic.
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.
For context, I am preparing Jenkins images for a project where pre-built pre-configured containers would act as automation servers with logging and UI for a specific business purpose, embedded on offline devices. To make the implementation similar to our other (CI) workflows, we want to use the Jenkins Shared Libraries and Pipeline job definitions from Git. However to keep the footprint small (and remove potential leaks that could have been in git histories), the prepared images use shallow clones of our CI development repositories, as of some specific commit (branch tip, tag). The run-time deployments are offline and would not see any real "git remote" systems.
So the containers with Jenkins include a location with sub-directories, where each one is a bare git repository with one or more symbolically named git references (we may deliver several branches to shuffle production/troubleshooting code variants etc.) for histories just a single commit long, and no persistently defined remotes. Initially truly shallow commits were used (with git metadata saying that we should trust that invisible histories do exist somewhere, just not here), but this proved troublesome (throwing NPE from a constructor) as explored in this ticket. A workaround is possible, however the unexplained NPE is not nice so subsequent commits will try to address it.
During this effort I started with something I use for ages for JSL development: using a local filesystem repository (my active git workspace) as the Git source for configured Global Libraries. This works cleanly with paths and
file://URI schema alike, and (may be a separate bug or not) does not stumble uponhudson.plugins.git.GitSCM.ALLOW_LOCAL_CHECKOUTproperty protection, at least not when configuring and checking branch names in$JENKINS_URL/configureUI (Jenkins did complain in subsequent@Libraryloads when instantiating jobs). It also did not seem to mind using shallow commits in the source repository for branch-based references to@Libraryloads.Expanding this experience to "Pipeline from SCM" failed for me with (default) Lightweight checkouts, with job run attempts instantly logging the NPE:
Disabling Lightweight checkouts did not crash instantly, but stumbled on that protective property (not a show-stopper, just a point for comparison):
After some drilling in the filesystem with consultations from ChatGPT, the root cause seems to have been constrained to the use of shallow branch as the desired source: at least in
$JENKINS_HOME/caches/git-$HASH/directories made as part of further checkout by default (probably not needed for this setup, but whatever), the git index and sample hook files were instantiated, but therefsdirectory remained empty. With manual reproduction, git actively refused the shallow source (see last line):As the result, when the plugin makes a lookup for
refs/heads/stagingorrefs/heads/origin/stagingin the cloned repository, it finds nothing and the constructor ends up withfindRef(head) == nullin https://github.com/jenkinsci/git-plugin/blob/git-5.10.1/src/main/java/jenkins/plugins/git/GitSCMFileSystem.java#L117:called from https://github.com/jenkinsci/git-plugin/blob/git-5.10.1/src/main/java/jenkins/plugins/git/GitSCMFileSystem.java#L407:
(note that default
remoteName=="origin"is valid for the cloned repo, just not for the original local one).For our local remediation, I used
git commit-tree(as replicated in the PR'ed test case) to forge a complete single-commit git history in the expected branch name, as the starting and only commit of the branch.ChatGPT suggested that we could also
Maybe this suggestion should be explored too. For now I plan to implement a meaningful message instead of unhelpful NPE via something like:
Testing done
Problem detected during setup.
Minimized and reproduced with help of AI.
Experience used to make a reproducer in the test cases added and posted here; they should hopefully confirm fixes later on.
Submitter checklist