Jenkins拉取请求克隆仓库失败问题求助
问题:Jenkins PR构建时Git克隆失败(Docker代理环境)
环境与现象
- Jenkins版本:2.452.1
- 配置:已在
Nodes > Clouds中配置Docker代理用于项目构建 - 异常:所有分支可正常构建,但创建PR(拉取请求)时出现克隆远程仓库失败
- 额外发现:
xxxx-scm-key.txt文件中Git URL被重复写入两次:git https://URL.test.git https://URL.test.git
报错日志
> git init /var/lib/jenkins/workspace/csf_PR-70@script/ecaff230533314b7e10ef114b9d082e # timeout=10 ERROR: Error cloning remote repo 'origin' hudson.plugins.git.GitException: Could not init /var/lib/jenkins/workspace/csf_PR-70@script/ecaff230533314b7e10ef114b9d082e at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$5.execute(CliGitAPIImpl.java:1073) at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$2.execute(CliGitAPIImpl.java:819) at hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:1226) at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1309) at org.jenkinsci.plugins.workflow.steps.scm.SCMStep.checkout(SCMStep.java:136) at org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition.create(CpsScmFlowDefinition.java:167) at org.jenkinsci.plugins.workflow.multibranch.SCMBinder.create(SCMBinder.java:143) at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:311) at hudson.model.ResourceController.execute(ResourceController.java:101) at hudson.model.Executor.run(Executor.java:442) Caused by: hudson.plugins.git.GitException: Error performing git command: git init /var/lib/jenkins/workspace/csf_PR-70@script/ecaff230533314b7e10ef114b9d082e at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2858) at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2762) at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2757) at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommand(CliGitAPIImpl.java:2051) at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$5.execute(CliGitAPIImpl.java:1071) ... 9 more Caused by: java.io.IOException: Cannot run program "git" (in directory "/var/lib/jenkins/workspace/csf_PR-70@script/ecaff230533314b7e10ef114b9d082e"): error=0, Failed to exec spawn helper: pid: 1532062, exit value: 1 at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1143) at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1073) at hudson.Proc$LocalProc.<init>(Proc.java:252) at hudson.Proc$LocalProc.<init>(Proc.java:221) at hudson.Launcher$LocalLauncher.launch(Launcher.java:994) at hudson.Launcher$ProcStarter.start(Launcher.java:506) at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2835) ... 13 more Caused by: java.io.IOException: error=0, Failed to exec spawn helper: pid: 1532062, exit value: 1 at java.base/java.lang.ProcessImpl.forkAndExec(Native Method) at java.base/java.lang.ProcessImpl.<init>(ProcessImpl.java:314) at java.base/java.lang.ProcessImpl.start(ProcessImpl.java:244) at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1110) ... 19 more ERROR: Error cloning remote repo 'origin' ERROR: Maximum checkout retry attempts reached, aborting ERROR: Error cloning remote repo 'origin'
解决方法
1. 修复重复的Git URL配置
- 编辑
xxxx-scm-key.txt文件,删除重复的Git URL,修正为正确格式:git https://URL.test.git - 检查Jenkins Multibranch Pipeline的分支源配置,确认PR触发器的SCM设置中没有重复添加同一远程仓库URL的情况。
2. 解决Docker代理的Git执行异常
- Java版本适配:若Docker代理镜像使用Java 16+,添加JVM启动参数
-Djdk.lang.Process.launchMechanism=vfork到Jenkins代理的配置中,解决Failed to exec spawn helper错误 - Git环境验证:确保Docker代理镜像中已安装Git工具,且
git命令在系统PATH中可直接调用 - 目录权限检查:确认代理容器内
/var/lib/jenkins/workspace/路径拥有可读写权限,保证Jenkins用户能创建并初始化Git仓库
3. 重新加载PR构建配置
- 在Jenkins中触发Multibranch Pipeline的「重新扫描分支」操作,让系统重新加载SCM配置
- 验证PR构建的凭据配置,确保拉取代码使用的凭据有权限访问目标Git仓库
内容的提问来源于stack exchange,提问作者GeoCom
相关产品推荐
相关产品推荐

