Jenkins 无法在 Windows 上通过 Git/SSH 克隆 Git 存储库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7850395/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 08:50:52  来源:igfitidea点击:

Jenkins can not clone Git repository over Git/SSH on Windows

windowsgitcontinuous-integrationhudsonjenkins

提问by ?eljko Filipin

I have successfully cloned Git repository in Jenkins over Git/SSH on Windows 2008 32-bit. When I tried to do the same on Windows 2008 64-bit, Console Outputpage gets stuck here:

我已经在 Windows 2008 32 位上通过 Git/SSH 成功克隆了 Jenkins 中的 Git 存储库。当我尝试在 Windows 2008 64 位上执行相同操作时,控制台输出页面卡在此处:

Démarré par l'utilisateur anonymous
Checkout:book / C:\Jenkins\workspace\book - hudson.remoting.LocalChannel@1da691a
Using strategy: Default
Last Built Revision: Revision 5d7ce4ae23c91fb201ee005e6db17bcd795ca965 (origin/HEAD, origin/master)
Checkout:book / C:\Jenkins\workspace\book - hudson.remoting.LocalChannel@1da691a
Cloning the remote Git repository
Cloning repository origin

When I stop the build (after a few minutes of being stuck there), I get the rest of the error message:

当我停止构建时(被卡在那里几分钟后),我收到了其余的错误消息:

ERROR: Error cloning remote repo 'origin' : Could not clone [email protected]:zeljkofilipin/watirbook.git
ERROR: Cause: Error performing command: C:\Git\bin\git.exe clone --progress -o origin [email protected]:zeljkofilipin/watirbook.git C:\Jenkins\workspace\book
null
Trying next repository
ERROR: Could not clone repository
FATAL: Could not clone
hudson.plugins.git.GitException: Could not clone
    at hudson.plugins.git.GitSCM.invoke(GitSCM.java:1042)
    at hudson.plugins.git.GitSCM.invoke(GitSCM.java:968)
    at hudson.FilePath.act(FilePath.java:785)
    at hudson.FilePath.act(FilePath.java:767)
    at hudson.plugins.git.GitSCM.checkout(GitSCM.java:968)
    at hudson.model.AbstractProject.checkout(AbstractProject.java:1193)
    at hudson.model.AbstractBuild$AbstractRunner.checkout(AbstractBuild.java:567)
    at hudson.model.AbstractBuild$AbstractRunner.run(AbstractBuild.java:455)
    at hudson.model.Run.run(Run.java:1404)
    at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:46)
    at hudson.model.ResourceController.execute(ResourceController.java:88)
    at hudson.model.Executor.run(Executor.java:230)
  • I can clone the repository via Git read-only URL git://github.com/zeljkofilipin/watirbook.gitfrom Jenkins on both machines
  • I can clone via Git/SSH URL [email protected]:zeljkofilipin/watirbook.gitfrom the command line on both machines
  • I can clone via Git/SSH URL from Jenkins on 32-bit machine, but not on 64-bit machine.
  • 我可以git://github.com/zeljkofilipin/watirbook.git在两台机器上通过 Jenkins 的Git 只读 URL 克隆存储库
  • 我可以[email protected]:zeljkofilipin/watirbook.git从两台机器上的命令行通过 Git/SSH URL 进行克隆
  • 我可以在 32 位机器上通过 Jenkins 通过 Git/SSH URL 进行克隆,但不能在 64 位机器上进行克隆。

The only difference I can notice between the two machines (not counting that one is a virtual machine on my laptop, and another is a real machine in Switzerland) is that the first one is 32-bit and the second one is 64-bit.

我能注意到两台机器之间的唯一区别(不算一台是我笔记本电脑上的虚拟机,另一台是瑞士的真机)是第一台是 32 位,第二台是 64 位。

Not sure if that could be related, but 32-bit machine has location set to Croatia, and 64-bit machine to Switzerland (as you can see from Git output in French).

不确定这是否相关,但是 32 位机器的位置设置为克罗地亚,而 64 位机器的位置设置为瑞士(正如您从法语 Git 输出中看到的那样)。

For more information please see my blog post: Jenkins, Windows and Git

有关更多信息,请参阅我的博客文章:Jenkins、Windows 和 Git

回答by inger

I've gone through these pains recently. Especially frustrating is the lack of error logs in this scenario: probably because MSysgit prompts user on the console when trying to recover - which doesn't get through Jenkins console.

我最近经历了这些痛苦。尤其令人沮丧的是在这种情况下缺少错误日志:可能是因为 MSysgit 在尝试恢复时会在控制台上提示用户 - 这不会通过 Jenkins 控制台。

Based on my experience here are a few key elements to watch for:

根据我的经验,这里有几个需要注意的关键要素:

  1. a mix of both Msysgit and Cygwin installed: MSysgit worked better for me- but I assume you're using that too
  2. some people have more luck with <MSYSGIT_ROOT>\cmd\git.cmdthan <MSYSGIT_ROOT>\bin\git.exe
  3. making sure your slave runs as the same user (which is not the default upon service-based installs).. - oh I see you got that too
  4. setting HOMEvariable for windows slaves explicity
  5. basically make sure the same .ssh keys are reached when under Jenkins.
  6. for debugging, I found it useful to create a test job with no SCM, but run git clonein an "Execute shell/batch" build step. That should reveal a bit more info. BTW, you can do an envin the same step and maybe ls %HOME%/.ssh
  1. 安装了 Msysgit 和 Cygwin 的混合:MSysgit 对我来说效果更好 - 但我假设你也在使用它
  2. 有些人的运气<MSYSGIT_ROOT>\cmd\git.cmd<MSYSGIT_ROOT>\bin\git.exe
  3. 确保您的奴隶以同一用户身份运行(这不是基于服务的安装的默认设置).. - 哦,我看到你也明白了
  4. HOME明确地为 Windows 从站设置变量
  5. 基本上确保在 Jenkins 下达到相同的 .ssh 密钥。
  6. 对于调试,我发现创建一个没有 SCM 的测试作业很有用,但git clone在“执行 shell/批处理”构建步骤中运行。这应该会透露更多信息。顺便说一句,你可以env在同一步骤中做一个,也许ls %HOME%/.ssh

I think the above is what gave me a working a Windows 7 64bit Jenkins slave with git support - although I thought this had more to do with some other fine config detail than with 64 vs 32 bits. Good luck anyhow!

我认为以上是什么给了我一个支持 git 的 Windows 7 64 位 Jenkins 从站 - 尽管我认为这与其他一些精细的配置细节有关,而不是 64 位和 32 位。无论如何祝你好运!

回答by Shanmu

In the latest version of git, had to use %GIT_HOME%/cmd/git.exe, rather than %GIT_HOME%/bin/git.exe and figuring out the home directory of the user running the jenkins service.

在最新版本的 git 中,不得不使用 %GIT_HOME%/cmd/git.exe,而不是 %GIT_HOME%/bin/git.exe 并找出运行 jenkins 服务的用户的主目录。

回答by mehmet6parmak

Another issue i faced with was, ssh.exe was not looking at the %userprofile%/.sshfolder for the key files. Instead it was looking to the folder C:\Program Files (x86)\Git\.sshwhich was empty and which causes a hang due to ssh authentication prompt on the machine where git repo located.

我面临的另一个问题是,ssh.exe 没有查看%userprofile%/.ssh密钥文件的文件夹。相反,它正在查找C:\Program Files (x86)\Git\.ssh空的文件夹,该文件夹由于 git repo 所在机器上的 ssh 身份验证提示而导致挂起。

We just copied the key files under %userprofile%/.sshto C:\Program Files (x86)\Git\.sshand the problem is resolved.

我们只是将关键文件复制到 下%userprofile%/.sshC:\Program Files (x86)\Git\.ssh问题就解决了。

回答by dkjkj

Notes from a hard learned lesson. I had problems getting the ssh to work running Jenkins as a named user account for ssh+git.

来自一个艰苦的教训的笔记。我在将 Jenkins 作为 ssh+git 的命名用户帐户运行时遇到问题。

Here is what I had to do to solve the problem:

这是我必须做的来解决这个问题:

  1. Generate the key using ssh-keygen (note where they are located)
  2. Set "HOME" to this location
  1. 使用 ssh-keygen 生成密钥(注意它们所在的位置)
  2. 将“HOME”设置为此位置

I tried with puttygen and GET_SSH=plink that all failed very bad but no clear errors.

我尝试使用 puttygen 和 GET_SSH=plink ,但都失败了,但没有明显错误。

回答by user33994

When you have to use any configuration options from a per-user configuration file eg. ~/.ssh/config you can put them in C:\Program Files (x86)\Git\etc\ssh\ssh_config, the key files can be put in C:\Program Files (x86)\Git.ssh

当您必须使用每个用户配置文件中的任何配置选项时,例如。~/.ssh/config 可以放在C:\Program Files (x86)\Git\etc\ssh\ssh_config,关键文件可以放在C:\Program Files (x86)\Git.ssh

回答by AVG

If your account is attached to domain. Then you need to make sure user for which the Jenkins Slave is ran. For the purpose open Settings->Propertiesof "Jenkins Slave"->Log On. and choose necessary userfrom domainfor correct execution.

如果您的帐户附加到域。然后,您需要确保运行 Jenkins Slave 的用户。为此,打开Settings-> Properties of "Jenkins Slave"-> Log On。并从域中选择必要的用户以正确执行。

回答by Cathy

Since my Windows Jenkins was a slave, I needed to configure that node to find the git in cmd instead of bin as described by inger. To do this, go to Manage Jenkins, Manage Nodes, click on the appropriate node, click on Configure and then go to the Tool Locations. Find git in the drop-down and then specify the path to git.exe (including git.exe), like C:\Program Files\Git\cmd\git.exe.

由于我的 Windows Jenkins 是从属设备,因此我需要配置该节点以在 cmd 中查找 git 而不是 inger 所描述的 bin。为此,请转到管理 Jenkins、管理节点,单击相应的节点,单击配置,然后转到工具位置。在下拉菜单中找到git,然后指定git.exe的路径(包括git.exe),比如C:\Program Files\Git\cmd\git.exe。

I confirmed that the cmd/git.exe worked differently than the bin/git.exe from both command-line and with a temporary jenkins job using the git command (instead of an scm repo).

我确认 cmd/git.exe 与命令行中的 bin/git.exe 和使用 git 命令(而不是 scm repo)的临时 jenkins 作业的工作方式不同。

回答by Anand Bansal

https://wiki.jenkins-ci.org/display/JENKINS/GitHub+Plugin

https://wiki.jenkins-ci.org/display/JENKINS/GitHub+Plugin

Just add a ssh-enabled user logon to Jenkins and it should work smoothly.

只需向 Jenkins 添加一个启用 ssh 的用户登录,它应该可以顺利运行。