詹金斯不能通过ssh克隆子模块,而cmd可以

发布于 2025-02-12 13:27:56 字数 6355 浏览 0 评论 0原文

Windows CMD中的Windows 10 CMD :

git clone https://bbk.example.com/scm/myproject/myrepository.git
cd myrepository
git submodule update --init --recursive

一切都很好。即使是通过SSH进行的git子模块也可以。

子模块是在SSH下添加的,我希望它像这样。

这是.gitModules:

[submodule "submodules/validator"]
    path = submodules/validator
    url = ssh://[email protected]:7999/myproject/validator.git

位置:

where git
C:\Program Files\Git\cmd\git.exe
where ssh
C:\Windows\System32\OpenSSH\ssh.exe

我为Jenkins设置了相同的GIT路径。并添加config,“分支来源”下的jenkins行为:

Advanced sub-modules behaviours
- Recursively update submodules: ticked
- Use credentials from default remote of parent repository: ticked
- Path of the reference repo to use during submodule update (empty)

添加了ssh 的“行为”选项结帐,并添加了SSH凭据。


在詹金斯(Jenkins)

,在詹金斯(Jenkins)下运行时,它会失败错误:不能产生SSH:没有这样的文件或目录

using GIT_ASKPASS to set credentials userpass
 > git fetch --no-tags --force --progress -- https://bbk.example.com/scm/myproject/myrepository.git +refs/heads/bug/AUTO-534/AUTO-744:refs/remotes/origin/bug/AUTO-534/AUTO-744 # timeout=10
Checking out Revision 2b300d6f20e615894152bdf1aab13efec55eed16 (bug/AUTO-534/AUTO-744)
 > git config core.sparsecheckout # timeout=10
 > git checkout -f 2b300d6f20e615894152bdf1aab13efec55eed16 # timeout=10
Commit message: "test"
 > git rev-list --no-walk 2b300d6f20e615894152bdf1aab13efec55eed16 # timeout=10
 > git remote # timeout=10
 > git submodule init # timeout=10
 > git submodule sync # timeout=10
 > git config --get remote.origin.url # timeout=10
 > git submodule init # timeout=10
 > git config -f .gitmodules --get-regexp ^submodule\.(.+)\.url # timeout=10
 > git config --get submodule.submodules/validator.url # timeout=10
 > git remote # timeout=10
 > git config --get remote.origin.url # timeout=10
 > git config -f .gitmodules --get submodule.submodules/validator.path # timeout=10
using GIT_ASKPASS to set credentials userpass
 > git submodule update --init --recursive submodules/validator # timeout=10
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
hudson.plugins.git.GitException: Command "git submodule update --init --recursive submodules/validator" returned status code 1:
stdout: 
stderr: Cloning into 'C:/ProgramData/Jenkins/.jenkins/workspace/ation-core_bug_AUTO-534_AUTO-744/submodules/validator'...
error: cannot spawn ssh: No such file or directory
fatal: unable to fork
fatal: clone of 'ssh://[email protected]:7999/myproject/validator.git' into submodule path 'C:/ProgramData/Jenkins/.jenkins/workspace/ation-core_bug_AUTO-534_AUTO-744/submodules/validator' failed
Failed to clone 'submodules/validator'. Retry scheduled
Cloning into 'C:/ProgramData/Jenkins/.jenkins/workspace/ation-core_bug_AUTO-534_AUTO-744/submodules/validator'...
error: cannot spawn ssh: No such file or directory
fatal: unable to fork
fatal: clone of 'ssh://[email protected]:7999/myproject/validator.git' into submodule path 'C:/ProgramData/Jenkins/.jenkins/workspace/ation-core_bug_AUTO-534_AUTO-744/submodules/validator' failed
Failed to clone 'submodules/validator' a second time, aborting

    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2671)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:2096)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.access$500(CliGitAPIImpl.java:84)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$7.lambda$execute$0(CliGitAPIImpl.java:1505)
    at com.google.common.util.concurrent.TrustedListenableFutureTask$TrustedFutureInterruptibleTask.runInterruptibly(TrustedListenableFutureTask.java:131)
    at com.google.common.util.concurrent.InterruptibleTask.run(InterruptibleTask.java:74)
    at com.google.common.util.concurrent.TrustedListenableFutureTask.run(TrustedListenableFutureTask.java:82)
    at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at com.google.common.util.concurrent.MoreExecutors$DirectExecutorService.execute(MoreExecutors.java:323)
    at java.base/java.util.concurrent.ExecutorCompletionService.submit(ExecutorCompletionService.java:184)
    at org.jenkinsci.plugins.gitclient.cgit.GitCommandsExecutor.submitRemainingCommand(GitCommandsExecutor.java:98)
    at org.jenkinsci.plugins.gitclient.cgit.GitCommandsExecutor.invokeAll(GitCommandsExecutor.java:87)
Caused: hudson.plugins.git.GitException
    at org.jenkinsci.plugins.gitclient.cgit.GitCommandsExecutor.checkResult(GitCommandsExecutor.java:110)
    at org.jenkinsci.plugins.gitclient.cgit.GitCommandsExecutor.invokeAll(GitCommandsExecutor.java:91)
    at org.jenkinsci.plugins.gitclient.cgit.GitCommandsExecutor.invokeAll(GitCommandsExecutor.java:49)
    at org.jenkinsci.plugin

emoverition

jenkins版本:

java -jar "C:\Program Files\Jenkins\jenkins.war" --version
2.332.3

插件:<代码> BitBucket Server IntegrationVersion (3.2.2

我的系统环境变量:

GIT_SSH = C:/Windows/System32/OpenSSH/ssh.exe

我已经通过PowerShell启用了SSH,我想这样使用它:

Set-Service -Name ssh-agent -StartupType Manual
Start-Service ssh-agent
ssh-add ~\.ssh\id_rsa

我即使主要存储库是通过HTTP,才能通过SSH下载ssh。

笔记: 删除詹金斯的行为并在詹金斯内部添加命令

sh 'set GIT_SSH=C:\\Windows\\System32\\OpenSSH\\ssh.exe'
sh 'git submodule update --init --recursive'

会导致相同的错误。即使使用/而不是\\也不会修复它。


最后

如何解决此错误?

error: cannot spawn ssh: No such file or directory

Under Windows 10 cmd

In windows cmd:

git clone https://bbk.example.com/scm/myproject/myrepository.git
cd myrepository
git submodule update --init --recursive

Everything is fine. Even git submodule via SSH is fine.

The submodule is added under SSH and I want it to be like this.

Here is .gitmodules:

[submodule "submodules/validator"]
    path = submodules/validator
    url = ssh://[email protected]:7999/myproject/validator.git

Locations:

where git
C:\Program Files\Git\cmd\git.exe
where ssh
C:\Windows\System32\OpenSSH\ssh.exe

I set the same git path for Jenkins. And add Jenkins behavior under config, 'Branch Sources':

Advanced sub-modules behaviours
- Recursively update submodules: ticked
- Use credentials from default remote of parent repository: ticked
- Path of the reference repo to use during submodule update (empty)

Also the behavior option Checkout over SSH is added and the SSH credential is added.


Under Jenkins

When running under Jenkins, it fails with error: cannot spawn ssh: No such file or directory:

using GIT_ASKPASS to set credentials userpass
 > git fetch --no-tags --force --progress -- https://bbk.example.com/scm/myproject/myrepository.git +refs/heads/bug/AUTO-534/AUTO-744:refs/remotes/origin/bug/AUTO-534/AUTO-744 # timeout=10
Checking out Revision 2b300d6f20e615894152bdf1aab13efec55eed16 (bug/AUTO-534/AUTO-744)
 > git config core.sparsecheckout # timeout=10
 > git checkout -f 2b300d6f20e615894152bdf1aab13efec55eed16 # timeout=10
Commit message: "test"
 > git rev-list --no-walk 2b300d6f20e615894152bdf1aab13efec55eed16 # timeout=10
 > git remote # timeout=10
 > git submodule init # timeout=10
 > git submodule sync # timeout=10
 > git config --get remote.origin.url # timeout=10
 > git submodule init # timeout=10
 > git config -f .gitmodules --get-regexp ^submodule\.(.+)\.url # timeout=10
 > git config --get submodule.submodules/validator.url # timeout=10
 > git remote # timeout=10
 > git config --get remote.origin.url # timeout=10
 > git config -f .gitmodules --get submodule.submodules/validator.path # timeout=10
using GIT_ASKPASS to set credentials userpass
 > git submodule update --init --recursive submodules/validator # timeout=10
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
hudson.plugins.git.GitException: Command "git submodule update --init --recursive submodules/validator" returned status code 1:
stdout: 
stderr: Cloning into 'C:/ProgramData/Jenkins/.jenkins/workspace/ation-core_bug_AUTO-534_AUTO-744/submodules/validator'...
error: cannot spawn ssh: No such file or directory
fatal: unable to fork
fatal: clone of 'ssh://[email protected]:7999/myproject/validator.git' into submodule path 'C:/ProgramData/Jenkins/.jenkins/workspace/ation-core_bug_AUTO-534_AUTO-744/submodules/validator' failed
Failed to clone 'submodules/validator'. Retry scheduled
Cloning into 'C:/ProgramData/Jenkins/.jenkins/workspace/ation-core_bug_AUTO-534_AUTO-744/submodules/validator'...
error: cannot spawn ssh: No such file or directory
fatal: unable to fork
fatal: clone of 'ssh://[email protected]:7999/myproject/validator.git' into submodule path 'C:/ProgramData/Jenkins/.jenkins/workspace/ation-core_bug_AUTO-534_AUTO-744/submodules/validator' failed
Failed to clone 'submodules/validator' a second time, aborting

    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2671)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:2096)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.access$500(CliGitAPIImpl.java:84)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$7.lambda$execute$0(CliGitAPIImpl.java:1505)
    at com.google.common.util.concurrent.TrustedListenableFutureTask$TrustedFutureInterruptibleTask.runInterruptibly(TrustedListenableFutureTask.java:131)
    at com.google.common.util.concurrent.InterruptibleTask.run(InterruptibleTask.java:74)
    at com.google.common.util.concurrent.TrustedListenableFutureTask.run(TrustedListenableFutureTask.java:82)
    at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at com.google.common.util.concurrent.MoreExecutors$DirectExecutorService.execute(MoreExecutors.java:323)
    at java.base/java.util.concurrent.ExecutorCompletionService.submit(ExecutorCompletionService.java:184)
    at org.jenkinsci.plugins.gitclient.cgit.GitCommandsExecutor.submitRemainingCommand(GitCommandsExecutor.java:98)
    at org.jenkinsci.plugins.gitclient.cgit.GitCommandsExecutor.invokeAll(GitCommandsExecutor.java:87)
Caused: hudson.plugins.git.GitException
    at org.jenkinsci.plugins.gitclient.cgit.GitCommandsExecutor.checkResult(GitCommandsExecutor.java:110)
    at org.jenkinsci.plugins.gitclient.cgit.GitCommandsExecutor.invokeAll(GitCommandsExecutor.java:91)
    at org.jenkinsci.plugins.gitclient.cgit.GitCommandsExecutor.invokeAll(GitCommandsExecutor.java:49)
    at org.jenkinsci.plugin

Environment

Jenkins version:

java -jar "C:\Program Files\Jenkins\jenkins.war" --version
2.332.3

Plugin: Bitbucket Server IntegrationVersion (3.2.2)

My system environment variable:

GIT_SSH = C:/Windows/System32/OpenSSH/ssh.exe

I have enabled SSH via powershell and I want to use it this way:

Set-Service -Name ssh-agent -StartupType Manual
Start-Service ssh-agent
ssh-add ~\.ssh\id_rsa

I want submodule being downloaded via SSH only even if the main repo is via HTTP.

Note:
Removing the Jenkins behaviors and adding the commands inside the Jenkins

sh 'set GIT_SSH=C:\\Windows\\System32\\OpenSSH\\ssh.exe'
sh 'git submodule update --init --recursive'

Causes the same error. Even using / instead of \\ does not fix it.


Finally

How can I fix this error?

error: cannot spawn ssh: No such file or directory

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文