简体   繁体   中英

Issue with Jenkins and Git submodules

I am trying to get Jenkins working on a Windows PC and have found a weird issue with submodules.

I have a git repo with three submodules. After a while it seems I got Git itself working on Jenkins so a normal clone works. However the clone does not clone the submodules inside the main repo, so I checked the box to recursively update submodules.

在此处输入图片说明

However, when I run my job:

Started by user <User>
Building in workspace X:\Jenkins\<JobName>
- C:/Program Files/Git/bin/git.exe rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
- C:/Program Files/Git/bin/git.exe config remote.origin.url ssh://git@<server>/<repo>.git # timeout=10
Fetching upstream changes from  ssh://git@<server>/<repo>.git
- C:/Program Files/Git/bin/git.exe --version # timeout=10
using GIT_SSH to set credentials 
- C:/Program Files/Git/bin/git.exe fetch --tags --progress  ssh://git@<server>/<repo>.git +refs/heads/*:refs/remotes/origin/*
- C:/Program Files/Git/bin/git.exe rev-parse "refs/remotes/origin/master^{commit}" # timeout=10
- C:/Program Files/Git/bin/git.exe rev-parse "refs/remotes/origin/origin/master^{commit}" # timeout=10
Checking out Revision b13204ee1c6717a82d1c7a17922f2a477efd119d (refs/remotes/origin/master)
Commit message: "testinggg.."
- C:/Program Files/Git/bin/git.exe config core.sparsecheckout # timeout=10
- C:/Program Files/Git/bin/git.exe checkout -f b13204ee1c6717a82d1c7a17922f2a477efd119d
- C:/Program Files/Git/bin/git.exe rev-list b13204ee1c6717a82d1c7a17922f2a477efd119d # timeout=10
- C:/Program Files/Git/bin/git.exe remote # timeout=10
- C:/Program Files/Git/bin/git.exe submodule init # timeout=10
- C:/Program Files/Git/bin/git.exe submodule sync # timeout=10
- C:/Program Files/Git/bin/git.exe config --get remote.origin.url # timeout=10
- C:/Program Files/Git/bin/git.exe submodule init # timeout=10
- C:/Program Files/Git/bin/git.exe config -f .gitmodules --get-regexp ^submodule\.(.*)\.url # timeout=10
- C:/Program Files/Git/bin/git.exe config --get submodule.top.url # timeout=10
- C:/Program Files/Git/bin/git.exe remote # timeout=10
- C:/Program Files/Git/bin/git.exe config --get remote.origin.url # timeout=10
- C:/Program Files/Git/bin/git.exe config -f .gitmodules --get submodule.top.path # timeout=10
using GIT_SSH to set credentials 
- C:/Program Files/Git/bin/git.exe submodule update --init --recursive top
FATAL: Command "C:/Program Files/Git/bin/git.exe submodule update --init --recursive top" returned status code 1:
stdout: 
stderr: fatal: Needed a single revision
Unable to find current revision in submodule path 'top'

hudson.plugins.git.GitException: Command "C:/Program Files/Git/bin/git.exe submodule update --init --recursive top" returned status code 1:
stdout: 
stderr: fatal: Needed a single revision
Unable to find current revision in submodule path 'top'

    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1903)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:1622)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.access$300(CliGitAPIImpl.java:71)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$7.execute(CliGitAPIImpl.java:1076)
    at hudson.plugins.git.extensions.impl.SubmoduleOption.onCheckoutCompleted(SubmoduleOption.java:102)
    at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1182)
    at hudson.scm.SCM.checkout(SCM.java:495)
    at hudson.model.AbstractProject.checkout(AbstractProject.java:1276)
    at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:560)
    at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:86)
    at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:485)
    at hudson.model.Run.execute(Run.java:1735)
    at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
    at hudson.model.ResourceController.execute(ResourceController.java:97)
    at hudson.model.Executor.run(Executor.java:405)
Finished: FAILURE

What does Git mean when it says:

Needed a single revision Unable to find current revision in submodule path 'top'

I have looked around and found nothing :(

I have replicated this sequence of command on a normal shell and no error appeared.

Any help will be appreciated. Thanks!

To anybody getting similar issues, check the box for Jenkins to wipe out the local workspace and force repository clone once. That worked for me ;)

Apparently 'top' is one of your submodules. The main repo that contains submodules just stores a commit ID of each of the submodules as reference to them. I interpret the error message as if there is a commit ID for 'top' in the main repo that cannot be found (does not exist?) in 'top'. I'd check this to be sure about this.

In the last project I worked with Git submodules and Jenkins we didn't use the Git plugin's Advanced sub-modules behaviours but executed all the git submodule ... commands in a Builder: Execute shell step of the Conditional BuildStep Plugin . Conditional to be able to abort the build if something goes wrong during these Git commands.

top branch sha mismatched to the commited sha for the submodule.

Consider enabling "Update tracking submodules to tip of branch" option.

This may not work for tags though.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM