You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Jenkins agent节点克隆Git仓库报错Could not init工作目录问题咨询

Jenkins Agent节点Git克隆报错解决方案

问题背景

DevOps团队在自有服务器部署的Jenkins(未使用Azure、AWS云服务)主节点运行正常,在Agent节点执行项目克隆操作时抛出如下错误:

Building remotely on ___________ in workspace C:\workspace\_____
using credential ____
Cloning the remote Git repository
Cloning repository ssh://git@stash.____.com:7999/sup/_____.git
 > git init C:\workspace\____  timeout=10
ERROR: Error cloning remote repo 'origin'
hudson.plugins.git.GitException: Could not init C:\workspace\______
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$5.execute(CliGitAPIImpl.java:990)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$2.execute(CliGitAPIImpl.java:748)
    at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler$GitCommandMasterToSlaveCallable.call(RemoteGitImpl.java:161)
    at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler$GitCommandMasterToSlaveCallable.call(RemoteGitImpl.java:154)
    at hudson.remoting.UserRequest.perform(UserRequest.java:211)
    at hudson.remoting.UserRequest.perform(UserRequest.java:54)
    at hudson.remoting.Request$2.run(Request.java:369)
    at hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.java:72)
    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.lambda$newThread$0(Engine.java:117)
    at java.lang.Thread.run(Unknown Source)
    Suppressed: hudson.remoting.Channel$CallSiteStackTrace: Remote call to JNLP4-connect connection from Hostname/ IPAdress :42222 
        at hudson.remoting.Channel.attachCallSiteStackTrace(Channel.java:1788)
        at hudson.remoting.UserRequest$ExceptionResponse.retrieve(UserRequest.java:356)
        at hudson.remoting.Channel.call(Channel.java:998)
        at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler.execute(RemoteGitImpl.java:146)
        at sun.reflect.GeneratedMethodAccessor1542.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:497)
        at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler.invoke(RemoteGitImpl.java:132)
        at com.sun.proxy.$Proxy119.execute(Unknown Source)
        at hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:1122)
        at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1167)
        at hudson.scm.SCM.checkout(SCM.java:505)
        at hudson.model.AbstractProject.checkout(AbstractProject.java:1206)
        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:1856)
        at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
        at hudson.model.ResourceController.execute(ResourceController.java:97)
        at hudson.model.Executor.run(Executor.java:428)
Caused by: hudson.plugins.git.GitException: Error performing git command: git init C:\workspace\_______
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2437)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2360)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2356)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommand(CliGitAPIImpl.java:1916)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$5.execute(CliGitAPIImpl.java:988)
    ... 12 more

错误核心:Agent节点执行git init初始化工作目录失败

排查与解决步骤

  • 验证Agent节点Git安装配置
    远程登录Windows系统的Agent节点,打开cmd执行git --version,确认Git已正确安装且可执行路径已加入系统环境变量PATH。若提示命令不存在,重新安装Git,安装过程中勾选「Add Git to PATH for all users」选项,安装完成后重启Jenkins Agent服务生效。
  • 校验工作目录权限
    确认Jenkins Agent运行账号对C:\workspace\目录具备读写、创建子目录的完全控制权限,可手动在该路径下新建、删除文件验证权限是否正常。若权限不足,给Agent运行账号分配对应目录的完全控制权限,或更换工作目录到其他无权限限制的路径。
  • 清理损坏的工作目录
    若C:\workspace\____目录已存在,先手动删除整个目录,再重新触发构建,避免原有目录下存在损坏的.git目录、或被其他进程锁定无法写入导致git init失败。
  • 匹配Git版本兼容性
    若Agent节点Git版本与Jenkins主节点的Git插件版本不兼容,升级Jenkins Git插件到最新稳定版,或把Agent节点的Git版本更换为与主节点一致的版本。
  • 处理Windows路径长度限制
    Windows默认存在260字符的路径长度限制,若工作目录完整路径长度超出限制,可开启Windows长路径支持,或缩短工作目录的路径层级与名称长度。

内容的提问来源于stack exchange,提问作者KingRaja

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.13 23:33:02