Jenkins踩坑:ERROR: Error cloning remote repo 'origin'

最近在看《Jenkins 权威指南1》这本书,按照书中教程搭建了一套Jenkins,在构建首个作业时报错信息如下:

ERROR: Error cloning remote repo 'origin'

hudson.plugins.git.GitException: Could not init D:\DevInstall\Jenkins\workspace\game-of-life-default

at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$5.execute(CliGitAPIImpl.java:989)

at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$2.execute(CliGitAPIImpl.java:747)

at hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:1114)

at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1159)

at hudson.scm.SCM.checkout(SCM.java:505)

at hudson.model.AbstractProject.checkout(AbstractProject.java:1205)

at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:574)

at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:86)

at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:499)

at hudson.model.Run.execute(Run.java:1853)

at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)

at hudson.model.ResourceController.execute(ResourceController.java:97)

at hudson.model.Executor.run(Executor.java:427)

Caused by: hudson.plugins.git.GitException: Error performing git command: D:\DevInstall\Git\bin init D:\DevInstall\Jenkins\workspace\game-of-life-default

at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2436)

at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2359)

at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2355)

at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommand(CliGitAPIImpl.java:1915)

at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$5.execute(CliGitAPIImpl.java:987)

... 12 more

Caused by: java.io.IOException: Cannot run program "D:\DevInstall\Git\bin" (in directory "D:\DevInstall\Jenkins\workspace\game-of-life-default"): CreateProcess error=5, 拒绝访问。

先说一下我的Jenkins及相关工具安装环境(全是win7系统)
Jenkins:D:\DevInstall\jenkins

Git: D:\DevInstall\git

从报错信息来分析,有可能是以下几方面原因:

1) Jenkins全局工具指定Git安装路径不正确

Caused by: hudson.plugins.git.GitException: Error performing git command: D:\DevInstall\Git\bin init D:\DevInstall\Jenkins\workspace\game-of-life-default

因为这条信息中提到了git命令无法执行。

打开Jenkins——Manage Jenkins——Global Tool Configuration

找到Git的配置,我原先是这样添加的:

听同仁说windows下要指定路径到git.exe,修改如下:

保存后执行,报错信息依旧不变。。。。

考虑第2种原因

2) github与本地连接出问题,代码无法获取

之前的示例中,我是采用http形式,Credentials中添加了github的账号密码,但是书中推荐改成ssh形式,如下:

关于github与本机建立信任连接这里不描述,可以参加我的另外一篇文章,这里主要说的是在Jenkins的Credentials中还需添加认证凭据,步骤如下:

1、进入用户家目录 cd  ~

2、进入.ssh目录

3、读取id.rsa里的内容,并copy下来

4、Jenkins的构建作业的配置页面,添加凭据

5、填写如下:

点击add添加第4步中负责的密钥吗,点击保存,再次build,success了!

你可能感兴趣的:(Jenkins踩坑:ERROR: Error cloning remote repo 'origin')