最近在看《Jenkins 權威指南1》這本書慰技,按照書中教程搭建了一套Jenkins椭盏,在構建首個作業(yè)時報錯信息如下:
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及相關工具安裝環(huán)境(全是win7系統(tǒng))
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命令無法執(zhí)行掏颊。
打開Jenkins——Manage Jenkins——Global Tool Configuration
找到Git的配置,我原先是這樣添加的:
聽同仁說windows下要指定路徑到git.exe艾帐,修改如下:
保存后執(zhí)行乌叶,報錯信息依舊不變。柒爸。枉昏。。
考慮第2種原因
2) github與本地連接出問題揍鸟,代碼無法獲取
之前的示例中兄裂,我是采用http形式,Credentials中添加了github的賬號密碼阳藻,但是書中推薦改成ssh形式晰奖,如下:
關于github與本機建立信任連接這里不描述,可以參加我的另外一篇文章腥泥,這里主要說的是在Jenkins的Credentials中還需添加認證憑據匾南,步驟如下:
1、進入用戶家目錄 cd? ~
2蛔外、進入.ssh目錄
3蛆楞、讀取id.rsa里的內容,并copy下來
4夹厌、Jenkins的構建作業(yè)的配置頁面豹爹,添加憑據
5、填寫如下:
點擊add添加第4步中負責的密鑰嗎矛纹,點擊保存臂聋,再次build,success了!