jenkins windows slave 报错ERROR: Error cloning remote repo 'origin'

本文解决了一个关于Jenkins在执行Git Clone操作时遇到的问题,详细记录了错误信息及解决步骤,包括设置Tool Location、配置SSH密钥等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在slave上是git clone ssh是可以成功的,但是jenkins调用slave节点就报如下错误:

ERROR: Error cloning remote repo 'origin'
hudson.plugins.git.GitException: Could not init C:\lebo\workspace\repo1
	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$5.execute(CliGitAPIImpl.java:717)
	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$2.execute(CliGitAPIImpl.java:511)
	at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler$1.call(RemoteGitImpl.java:153)
	at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler$1.call(RemoteGitImpl.java:146)
	at hudson.remoting.UserRequest.perform(UserRequest.java:181)
	at hudson.remoting.UserRequest.perform(UserRequest.java:52)
	at hudson.remoting.Request$2.run(Request.java:336)
	at hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.java:68)
	at java.util.concurrent.FutureTask.run(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at hudson.remoting.Engine$1$1.run(Engine.java:98)
	at java.lang.Thread.run(Unknown Source)
	at ......remote call to JNLP4-connect connection from 192.168.8.211/192.168.8.211:49194(Native Method)
	at hudson.remoting.Channel.attachCallSiteStackTrace(Channel.java:1554)
	at hudson.remoting.UserResponse.retrieve(UserRequest.java:281)
	at hudson.remoting.Channel.call(Channel.java:839)
	at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler.execute(RemoteGitImpl.java:146)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler.invoke(RemoteGitImpl.java:132)
	at com.sun.proxy.$Proxy77.execute(Unknown Source)
	at hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:1083)
	at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1123)
	at hudson.scm.SCM.checkout(SCM.java:495)
	at hudson.model.AbstractProject.checkout(AbstractProject.java:1212)
	at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:560)
	at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:86)
	at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:485)
	at hudson.model.Run.execute(Run.java:1735)
	at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
	at hudson.model.ResourceController.execute(ResourceController.java:97)
	at hudson.model.Executor.run(Executor.java:415)
Caused by: hudson.plugins.git.GitException: Error performing command: git init C:\lebo\workspace\repo1
	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1931)
	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1892)
	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1888)
	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommand(CliGitAPIImpl.java:1533)
	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$5.execute(CliGitAPIImpl.java:715)
	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$2.execute(CliGitAPIImpl.java:511)
	at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler$1.call(RemoteGitImpl.java:153)
	at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler$1.call(RemoteGitImpl.java:146)
	at hudson.remoting.UserRequest.perform(UserRequest.java:181)
	at hudson.remoting.UserRequest.perform(UserRequest.java:52)
	at hudson.remoting.Request$2.run(Request.java:336)
	at hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.java:68)
	at java.util.concurrent.FutureTask.run(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at hudson.remoting.Engine$1$1.run(Engine.java:98)
	at java.lang.Thread.run(Unknown Source)
Caused by: java.io.IOException: Cannot run program "git" (in directory "C:\lebo\workspace\repo1"): CreateProcess error=2, 系统找不到指定的文件。
	at java.lang.ProcessBuilder.start(Unknown Source)
	at hudson.Proc$LocalProc.<init>(Proc.java:249)
	at hudson.Proc$LocalProc.<init>(Proc.java:218)
	at hudson.Launcher$LocalLauncher.launch(Launcher.java:930)
	at hudson.Launcher$ProcStarter.start(Launcher.java:450)
	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1920)
	... 16 more
Caused by: java.io.IOException: CreateProcess error=2, 系统找不到指定的文件。
	at java.lang.ProcessImpl.create(Native Method)
	at java.lang.ProcessImpl.<init>(Unknown Source)
	at java.lang.ProcessImpl.start(Unknown Source)
	... 22 more
ERROR: Error cloning remote repo 'origin'
Finished: FAILURE


解决:需要在jenkins master上设置Tool Location,如下:

此外:首次下载,需要slave设置ssh-key 到gerrit上,并需要clone一次,选择主机信任。

1.ssh-keygen -t rsa -C anl@hpplay.cn

2.cat ~/.ssh/id_rsa.pub

3.git config --global user.email "anl@hpplay.cn"

4.git config --global user.name "anl"

5.git config --global core.editor vim

6.git clone ssh:xxxxxxx

转载于:https://www.cnblogs.com/zndxall/p/9052791.html

### Jenkins ERROR: Error cloning remote repo 'origin' 的解决方案 #### 问题原因分析 该错误通常由以下几个原因之一引起: 1. **Git路径未正确配置**:如果Jenkins无法找到系统的Git可执行文件,则会抛出此错误[^1]。 2. **权限不足**:目标远程仓库可能需要身份验证,而当前的Jenkins作业缺少有效的SSH密钥或用户名/密码认证信息。 3. **网络连接不稳定**:当Jenkins尝试克隆远程仓库时,由于网络超时或其他网络异常可能导致失败[^4]。 --- #### 解决方案 ##### 方法一:确认并修复Git路径配置 在Windows环境下运行Jenkins时,需确保已正确定位到`git.exe`的位置。可以通过以下步骤完成配置: 1. 进入Jenkins主页 -> 系统管理 -> 全局工具配置; 2. 定位至Git部分,在“Path to Git executable”字段中输入完整的Git路径(例如 `C:\Program Files\Git\bin\git.exe` 或者 `D:\Git\cmd\git.exe`),然后保存设置。 对于Linux环境下的节点,也需要检查是否已经安装了Git以及其版本是否满足需求。如果没有安装或者版本过低,请先更新系统中的Git软件包后再重新测试。 ##### 方法二:调整高级克隆行为选项 通过修改项目的源码管理设置来优化克隆过程参数可能会缓解某些特定场景下的问题发生率。具体操作如下所示: - 在项目配置页面内的Source Code Management区域点击Add按钮展开更多可用的行为列表; - 添加名为Advanced Clone Behaviors的新条目,并启用其中几个关键开关如Fetch Tags, Shallow Clone等同时设定合理的数值比如Shallow Clone Depth设成较小整数形式减少传输数据量大小从而加快速度;另外还可以适当延长Timeout时间以便应对较慢链接状况[^3]: ```plaintext 勾选项: Fetch tags Shallow clone 参数值: Shallow clone depth = 1 Timeout (in minutes) for clone and fetch operations = 15 ``` ##### 方法三:提供正确的访问凭证 如果是私有存储库导致的身份验证失败情形的话,则应该按照下面指示补充相应的授权资料进去相应位置当中去才行得通哦! 前往Job Configuration界面里的Credentials Manager板块寻找合适类型的Credential entry创建出来关联上合适的Private Key File或者是Username & Password组合依据实际情况选用其中之一即可解决问题啦!记得要保证所填入的信息准确无误并且具有足够的读写权限才可以正常使用呢[^2]. 最后别忘了重启服务让更改生效哟~ 如果是在容器内部署的服务则可以直接利用docker restart命令快速实现这一目的哈~ --- ### 总结代码示例 以下是基于上述描述的一个简单脚本用于自动化处理部分常见情景: ```bash #!/bin/bash # Step A - Verify GIT Installation on Host Machine which git || sudo apt-get install git -y # Step B - Restart Dockerized Jenkins Instance After Changes Made To Configurations. sudo docker restart myjenkins ``` ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值