在Windows 7下使用Jenkins正确配置Git

时间:2012-10-05 07:04:52

标签: git windows-7 jenkins

我在Windows 7下使用Jenkins 1.484,我在克隆git存储库方面遇到了麻烦。

我已经正确配置了Git,但是当我尝试克隆存储库时,这需要永远而且永远不会成功。它刚刚停止:

git --version git版本1.7.9.msysgit.0

如果在十分钟后我停止构建,那就是我所看到的:

ERROR: Error cloning remote repo 'origin' : Could not clone git@github.com:GBSA/Gottware-server.git
hudson.plugins.git.GitException: Could not clone git@github.com:GBSA/Gottware-server.git
    at hudson.plugins.git.GitAPI.clone(GitAPI.java:271)
    at hudson.plugins.git.GitSCM$2.invoke(GitSCM.java:1040)
    at hudson.plugins.git.GitSCM$2.invoke(GitSCM.java:982)
    at hudson.FilePath.act(FilePath.java:851)
    at hudson.FilePath.act(FilePath.java:824)
    at hudson.plugins.git.GitSCM.determineRevisionToBuild(GitSCM.java:982)
    at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1138)
    at hudson.model.AbstractProject.checkout(AbstractProject.java:1256)
    at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:589)
    at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:88)
    at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:494)
    at hudson.model.Run.execute(Run.java:1502)
    at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:46)
    at hudson.model.ResourceController.execute(ResourceController.java:88)
    at hudson.model.Executor.run(Executor.java:236)
Caused by: hudson.plugins.git.GitException: Error performing command: C:\Program Files (x86)\Git\bin\git.exe clone --progress -o origin git@github.com:GBSA/Gottware-server.git G:\jenkins\workspaces\gottwareproductiontests
    at hudson.plugins.git.GitAPI.launchCommandIn(GitAPI.java:870)
    at hudson.plugins.git.GitAPI.access$000(GitAPI.java:40)
    at hudson.plugins.git.GitAPI$1.invoke(GitAPI.java:267)
    at hudson.plugins.git.GitAPI$1.invoke(GitAPI.java:246)
    at hudson.FilePath.act(FilePath.java:851)
    at hudson.FilePath.act(FilePath.java:824)
    at hudson.plugins.git.GitAPI.clone(GitAPI.java:246)
    ... 14 more
Caused by: java.lang.InterruptedException
    at java.lang.ProcessImpl.waitFor(Native Method)
    at hudson.Proc$LocalProc.join(Proc.java:319)
    at hudson.Launcher$ProcStarter.join(Launcher.java:352)
    at hudson.plugins.git.GitAPI.launchCommandIn(GitAPI.java:851)
    ... 20 more
Trying next repository
ERROR: Could not clone repository
FATAL: Could not clone
hudson.plugins.git.GitException: Could not clone
    at hudson.plugins.git.GitSCM$2.invoke(GitSCM.java:1052)
    at hudson.plugins.git.GitSCM$2.invoke(GitSCM.java:982)
    at hudson.FilePath.act(FilePath.java:851)

如果恰恰相反,我尝试执行我从命令行配置的相同GIT,克隆成功

C:\Program Files (x86)\Git\bin>"C:\Program Files (x86)\Git\bin\git.exe" clone --progress -o origin git@github.com:GBSA/Gottware-server.git G:\jenkins\
workspaces\gottwareproductiontests
Cloning into 'G:\jenkins\workspaces\gottwareproductiontests'...
remote: Counting objects: 38007, done.
remote: Compressing objects: 100% (16268/16268), done.

出了什么问题?

1 个答案:

答案 0 :(得分:4)

在Windows上,Jenkins进程作为系统服务运行,因此它以SYSTEM用户身份运行,而不是使用您的帐户。您正在使用git@github.com类型的URL,因此尝试使用SSH,这需要从ssh代理(如pageant)或〜/ .ssh / identity以SYSTEM用户身份运行时找到ssh密钥。 / p>

最简单的解决方案是使用http或https传输。当您在执行构建时拉动而不是推动时,您不需要为这些协议配置用户名或密码。如果您的本地网络配置允许,您可以使用git协议(git://github.com / ...)。

或者,您可以使用sysinternals中的psexec以系统用户身份获取命令提示符并修复本地环境,以便ssh可以正常工作。 psexec -i -s cmd.exe将产生一个SYSTEM命令提示符,然后您可以运行msysGit bash shell并设置一个合适的ssh密钥以注册远程系统。我一直在XP上使用它 - 所以它可能不再适用于Win7。您还可以将Jenkins配置为另一个用户帐户运行,但我没有在本地使用该方法。