# Jenkins can't find private git submodules

**URL:** <https://community.jenkins.io/t/jenkins-cant-find-private-git-submodules/3008>\
**Category:** Ask a question\
**Tags:** question, git\
**Created:** [July 13, 2022, 1:41pm UTC](https://community.jenkins.io/t/jenkins-cant-find-private-git-submodules/3008 "2022-07-13T13:41:31Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![ShubhamGsource](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/shubhamgsource/32/1842_2.png) [@ShubhamGsource](https://community.jenkins.io/u/ShubhamGsource)\
**Post date:** [July 13, 2022, 1:41pm UTC](https://community.jenkins.io/t/jenkins-cant-find-private-git-submodules/3008/1 "2022-07-13T13:41:31Z")

</div>

I am trying to build a job. It is a Github project which has submodules. Even after enabling “Advanced sub-modules behaviours” and checking 1. Recursively update submodules and 2. Use credentials from default remote of parent repository. Jenkins job fails at the time of updating submodules.

```auto
> git.exe submodule update --init --recursive Source/TesserconCore # timeout=10
ERROR: Checkout failed
hudson.plugins.git.GitException: Command "git.exe submodule update --init --recursive Source/TesserconCore" returned status code 1:
stdout: 
stderr: Cloning into 'C:/ProgramData/Jenkins/.jenkins/workspace/Tessercon-Pipeline@script/d72c8f432eb5485df443e918b9cec288c17c5fb7c8389760c9532fed90d3aeab/Source/TesserconCore'...
remote: Repository not found.

```

---

<div class="post-metadata">

**Author:** ![MarkEWaite](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/markewaite/32/20_2.png) [@MarkEWaite](https://community.jenkins.io/u/MarkEWaite)\
**Post date:** [July 13, 2022, 2:47pm UTC](https://community.jenkins.io/t/jenkins-cant-find-private-git-submodules/3008/2 "2022-07-13T14:47:19Z")

</div>

> [@ShubhamGsource](#):
>
> `remote: Repository not found.`

I believe that is a command line git message that the remote git server cannot find the repository that is referenced in the submodule definition inside the parent git repository. Check that the submodule definition in the parent repository is correct and can retrieve the submodule outside of Jenkins.

---

<div class="post-metadata">

**Author:** ![ShubhamGsource](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/shubhamgsource/32/1842_2.png) [@ShubhamGsource](https://community.jenkins.io/u/ShubhamGsource)\
**Post date:** [July 14, 2022, 5:21am UTC](https://community.jenkins.io/t/jenkins-cant-find-private-git-submodules/3008/3 "2022-07-14T05:21:48Z")

</div>

When I try to clone this repository manually, Git do finds the submodule repositories and clones them perfectly. This problem is only with Jenkins.

---

<div class="post-metadata">

**Author:** ![halkeye](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/halkeye/32/8_2.png) [@halkeye](https://community.jenkins.io/u/halkeye)\
**Post date:** [July 14, 2022, 8:10am UTC](https://community.jenkins.io/t/jenkins-cant-find-private-git-submodules/3008/4 "2022-07-14T08:10:19Z")

</div>

How are the credentials being provided to git.exe? I don’t think windows has ssh agents.

When you say it works outside of Jenkins and thus Jenkins fault. Are you testing with the same user on the same server? Jenkins usually runs as a service account in Windows

---

<div class="post-metadata">

**Author:** ![ShubhamGsource](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/shubhamgsource/32/1842_2.png) [@ShubhamGsource](https://community.jenkins.io/u/ShubhamGsource)\
**Post date:** [July 14, 2022, 9:05am UTC](https://community.jenkins.io/t/jenkins-cant-find-private-git-submodules/3008/5 "2022-07-14T09:05:27Z")

</div>

I have generated a personal access token in Github. That, I have set as password for my Jenkins credential. My parent repository is getting cloned, but the issue is only when git tries to perform `submodule update --init --recursive`. Then only it fails with the above error message.

---

<div class="post-metadata">

**Author:** ![MarkEWaite](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/markewaite/32/20_2.png) [@MarkEWaite](https://community.jenkins.io/u/MarkEWaite)\
**Post date:** [July 14, 2022, 9:36am UTC](https://community.jenkins.io/t/jenkins-cant-find-private-git-submodules/3008/6 "2022-07-14T09:36:54Z")

</div>

The Jenkins git plugin submodule implementation may be getting in the way of what you’re trying to do. You might switch from performing `checkout scm` in your Pipeline to instead use the `withCredentials()` wrapper and perform the exact git command that you know work for you from the command line.

The [git plugin documentation](https://plugins.jenkins.io/git/#plugin-content-git-username-and-password-binding) includes an example that you might use something like this:

```nohighlight
pipeline {
    options {
        skipDefaultCheckout true
    }
    agent {
        label '!windows'
    }
    stages {
        stage('Checkout') {
            steps {
                withCredentials([GitUsernamePassword(credentialsId: 'your-credential', gitToolName: 'Default')]) {
                    sh '''
                    [-d bin] || git clone --recursive https://github.com/MarkEWaite/bin
                    cd bin && git pull --recurse-submodules
                    '''
                }
            }
        }
    }
}

```

---

<div class="post-metadata">

**Author:** ![ShubhamGsource](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/shubhamgsource/32/1842_2.png) [@ShubhamGsource](https://community.jenkins.io/u/ShubhamGsource)\
**Post date:** [July 18, 2022, 9:48am UTC](https://community.jenkins.io/t/jenkins-cant-find-private-git-submodules/3008/7 "2022-07-18T09:48:59Z")

</div>

When I added that script to checkout  
`stage('checkout') { steps { withCredentials([GitUsernamePassword(credentialsId: 'ShubhamThkr', gitToolName: 'Default')]) { sh ''' git pull --recurse-submodules ''' } } }`

I am getting an unknown error

```auto
[Pipeline] stage
[Pipeline] { (checkout)
[Pipeline] withCredentials
Masking supported pattern matches of %GIT_USERNAME% or %GIT_ASKPASS%
[Pipeline] {
[Pipeline] sh
[Pipeline] }
[Pipeline] // withCredentials
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Building)
Stage "Building" skipped due to earlier failure(s)
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Cooking)
Stage "Cooking" skipped due to earlier failure(s)
[Pipeline] }
[Pipeline] // stage

```

---

<div class="post-metadata">

**Author:** ![MarkEWaite](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/markewaite/32/20_2.png) [@MarkEWaite](https://community.jenkins.io/u/MarkEWaite)\
**Post date:** [July 18, 2022, 12:37pm UTC](https://community.jenkins.io/t/jenkins-cant-find-private-git-submodules/3008/8 "2022-07-18T12:37:44Z")

</div>

Aer you sure that you included the error message in your output? I can’t see any error message or any other indication of the failure.

Are you sure that the workspace already exists and has a local copy of the git repository at the point where you call `git pull`? The `git pull` command must be performed from a local copy of the repository. If you haven’t already cloned into that workspace, then there is no repository that can be used for the `git pull`.

---

<div class="post-metadata">

**Author:** ![ShubhamGsource](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/shubhamgsource/32/1842_2.png) [@ShubhamGsource](https://community.jenkins.io/u/ShubhamGsource)\
**Post date:** [July 18, 2022, 1:56pm UTC](https://community.jenkins.io/t/jenkins-cant-find-private-git-submodules/3008/9 "2022-07-18T13:56:26Z")

</div>

I changed submodule paths from http to ssh now they are getting cloned.  
But what I want to do is to pull these submodules using jenkinsfile but it fails to perform the action

```auto
 stage('Submodule update')
	  {
		  steps
		  {
			withCredentials([GitUsernamePassword(credentialsId: 'ShubhamThkr', gitToolName: 'Default')]) 
			  {
				sh('''
				git submodule init
				git submodule update
				''')
			  }
		  }
	  }

```

and logs are

```auto
[Pipeline] stage
[Pipeline] { (Submodule update)
[Pipeline] withCredentials
Masking supported pattern matches of %GIT_USERNAME% or %GIT_ASKPASS%
[Pipeline] {
[Pipeline] sh
[Pipeline] }
[Pipeline] // withCredentials
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Building)
Stage "Building" skipped due to earlier failure(s)
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Cooking)
Stage "Cooking" skipped due to earlier failure(s)

```

and

```auto
java.io.IOException: CreateProcess error=2, The system cannot find the file specified
	at java.base/java.lang.ProcessImpl.create(Native Method)
	at java.base/java.lang.ProcessImpl.<init>(ProcessImpl.java:487)
	at java.base/java.lang.ProcessImpl.start(ProcessImpl.java:154)
	at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1107)
	at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1071)
	at hudson.Proc$LocalProc.<init>(Proc.java:254)
	at hudson.Proc$LocalProc.<init>(Proc.java:223)
	at hudson.Launcher$LocalLauncher.launch(Launcher.java:997)
	at hudson.Launcher$ProcStarter.start(Launcher.java:509)
	at org.jenkinsci.plugins.durabletask.BourneShellScript.launchWithCookie(BourneShellScript.java:176)
	at org.jenkinsci.plugins.durabletask.FileMonitoringTask.launch(FileMonitoringTask.java:132)
	at org.jenkinsci.plugins.workflow.steps.durable_task.DurableTaskStep$Execution.start(DurableTaskStep.java:324)
	at org.jenkinsci.plugins.workflow.cps.DSL.invokeStep(DSL.java:322)
	at org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:196)
	at org.jenkinsci.plugins.workflow.cps.CpsScript.invokeMethod(CpsScript.java:124)
	at jdk.internal.reflect.GeneratedMethodAccessor3008.invoke(Unknown Source)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:98)
	at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
	at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1225)
	at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1034)
	at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:41)
	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
	at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:163)
	at org.kohsuke.groovy.sandbox.GroovyInterceptor.onMethodCall(GroovyInterceptor.java:23)
	at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onMethodCall(SandboxInterceptor.java:158)
	at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:161)
	at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:165)
	at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:135)
	at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:135)
	at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.methodCall(SandboxInvoker.java:17)
Caused: java.io.IOException: Cannot run program "nohup" (in directory "C:\ProjectWorkspace"): CreateProcess error=2, The system cannot find the file specified
	at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1128)
	at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1071)
	at hudson.Proc$LocalProc.<init>(Proc.java:254)
	at hudson.Proc$LocalProc.<init>(Proc.java:223)
	at hudson.Launcher$LocalLauncher.launch(Launcher.java:997)
	at hudson.Launcher$ProcStarter.start(Launcher.java:509)
	at org.jenkinsci.plugins.durabletask.BourneShellScript.launchWithCookie(BourneShellScript.java:176)
	at org.jenkinsci.plugins.durabletask.FileMonitoringTask.launch(FileMonitoringTask.java:132)
	at org.jenkinsci.plugins.workflow.steps.durable_task.DurableTaskStep$Execution.start(DurableTaskStep.java:324)
	at org.jenkinsci.plugins.workflow.cps.DSL.invokeStep(DSL.java:322)
	at org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:196)
	at org.jenkinsci.plugins.workflow.cps.CpsScript.invokeMethod(CpsScript.java:124)
	at jdk.internal.reflect.GeneratedMethodAccessor3008.invoke(Unknown Source)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:98)
	at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
	at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1225)
	at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1034)
	at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:41)
	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
	at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:163)
	at org.kohsuke.groovy.sandbox.GroovyInterceptor.onMethodCall(GroovyInterceptor.java:23)
	at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onMethodCall(SandboxInterceptor.java:158)
	at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:161)
	at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:165)
	at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:135)
	at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:135)
	at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.methodCall(SandboxInvoker.java:17)
	at WorkflowScript.run(WorkflowScript:40)
	at ___cps.transform___ (Native Method)
	at com.cloudbees.groovy.cps.impl.ContinuationGroup.methodCall(ContinuationGroup.java:86)
	at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.java:113)
	at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixArg(FunctionCallBlock.java:83)
	at jdk.internal.reflect.GeneratedMethodAccessor240.invoke(Unknown Source)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72)
	at com.cloudbees.groovy.cps.impl.ConstantBlock.eval(ConstantBlock.java:21)
	at com.cloudbees.groovy.cps.Next.step(Next.java:83)
	at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:174)
	at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:163)
	at org.codehaus.groovy.runtime.GroovyCategorySupport$ThreadCategoryInfo.use(GroovyCategorySupport.java:136)
	at org.codehaus.groovy.runtime.GroovyCategorySupport.use(GroovyCategorySupport.java:275)
	at com.cloudbees.groovy.cps.Continuable.run0(Continuable.java:163)
	at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.access$001(SandboxContinuable.java:18)
	at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.run0(SandboxContinuable.java:51)
	at org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:187)
	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:420)
	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$400(CpsThreadGroup.java:95)
	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:330)
	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:294)
	at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:67)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:139)
	at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
	at jenkins.security.ImpersonatingExecutorService$1.run(ImpersonatingExecutorService.java:68)
	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.lang.Thread.run(Thread.java:834)
Finished: FAILURE

```

this error message is shown after end of pipeline

---

<div class="post-metadata">

**Author:** ![MarkEWaite](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/markewaite/32/20_2.png) [@MarkEWaite](https://community.jenkins.io/u/MarkEWaite)\
**Post date:** [July 18, 2022, 2:27pm UTC](https://community.jenkins.io/t/jenkins-cant-find-private-git-submodules/3008/10 "2022-07-18T14:27:27Z")

</div>

> [@ShubhamGsource](#):
>
> I changed submodule paths from http to ssh now they are getting cloned.

The git plugin can only provide one type of credentials at a time to a git command. If the parent repository is using ssh protocol, then it must be authenticated with an ssh private key. If a submodule of that parent repository uses a private https repository, then it must be authenticated with a username / password.

Since submodule operations are performed by the git plugin with the same credentials that perform the initial `fetch`, the submodule must use the same protocol as the parent repository if you want to use the git plugin to perform submodule operations.

If the submodule is authenticated with a private key, then the `withCredentials` wrapper won’t help if it provides a username / password credential.

> [@ShubhamGsource](#):
>
> But what I want to do is to pull these submodules using jenkinsfile but it fails to perform the action

The `sh` step in Pipeline expects a POSIX-style shell (like bash, ksh, ash, etc.) as is provided on Unix systems (like Linux, FreeBSD, OpenBSD, and macOS). That is not generally available on Windows.

If you want to perform command line operations on Windows, you need to use the `bat`, `powershell`, or `pwsh` steps.

If you need to run on both Windows and Unix, you can use the `isUnix()` conditional to choose Unix compatible steps on one path and Windows compatible steps on the other path.
