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

Jenkins Windows代理无法克隆Git仓库问题求助

问题:Jenkins Windows代理克隆Git仓库时路径拼接错误

Jenkins运行在虚拟机VM1的Docker容器中,目标Git仓库所在的网络驱动器已挂载到Docker容器的/mnt/h/路径下。构建任务使用VM1上的Windows代理执行,克隆仓库时出现路径解析错误:

16:49:59 stderr: fatal: 'C:/Program Files/Git/mnt/h/GIT_NEW' does not appear to be a git repository

完整构建日志如下:

16:49:58 Started by user SmusJenkins
16:49:58 Running as SYSTEM
16:49:58 Building remotely on Smusjenkins VM (FAMUS) in workspace C:/Jenkins/workspace/FAMUS
16:49:58 The recommended git tool is: NONE
16:49:58 No credentials specified
16:49:58 Wiping out workspace first.
16:49:58 Cloning the remote Git repository
16:49:58 Cloning repository file:///mnt/h/GIT_NEW
16:49:58  > C:\Program Files\Git\bin\git.exe init C:\Jenkins\workspace\FAMUS # timeout=10
16:49:59 Fetching upstream changes from file:///mnt/h/GIT_NEW
16:49:59  > C:\Program Files\Git\bin\git.exe --version # timeout=10
16:49:59  > git --version # 'git version 2.38.1.windows.1'
16:49:59  > C:\Program Files\Git\bin\git.exe fetch --tags --force --progress -- file:///mnt/h/GIT_NEW +refs/heads/*:refs/remotes/origin/* # timeout=10
16:49:59 ERROR: Error cloning remote repo 'origin'
16:49:59 hudson.plugins.git.GitException: Command "C:\Program Files\Git\bin\git.exe fetch --tags --force --progress -- file:///mnt/h/GIT_NEW +refs/heads/*:refs/remotes/origin/*" returned status code 128:
16:49:59 stdout: 
16:49:59 stderr: fatal: 'C:/Program Files/Git/mnt/h/GIT_NEW' does not appear to be a git repository
16:49:59 fatal: Could not read from remote repository.
16:49:59 
16:49:59 Please make sure you have the correct access rights
16:49:59 and the repository exists.
16:49:59 
16:49:59    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2697)
16:49:59    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:2111)
16:49:59    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.access$500(CliGitAPIImpl.java:87)
16:49:59    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$1.execute(CliGitAPIImpl.java:623)
16:49:59    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$2.execute(CliGitAPIImpl.java:852)
16:49:59    at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler$GitCommandMasterToSlaveCallable.call(RemoteGitImpl.java:158)
16:49:59    at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler$GitCommandMasterToSlaveCallable.call(RemoteGitImpl.java:151)
16:49:59    at hudson.remoting.UserRequest.perform(UserRequest.java:211)
16:49:59    at hudson.remoting.UserRequest.perform(UserRequest.java:54)
16:49:59    at hudson.remoting.Request$2.run(Request.java:376)
16:49:59    at hudson.remoting.InterceptingExecutorService.lambda$wrap$0(InterceptingExecutorService.java:78)
16:49:59    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:317)
16:49:59    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
16:49:59    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
16:49:59    at java.base/java.lang.Thread.run(Thread.java:1589)
16:49:59    Suppressed: hudson.remoting.Channel$CallSiteStackTrace: Remote call to Smusjenkins VM
16:49:59        at hudson.remoting.Channel.attachCallSiteStackTrace(Channel.java:1784)
16:49:59        at hudson.remoting.UserRequest$ExceptionResponse.retrieve(UserRequest.java:356)
16:49:59        at hudson.remoting.Channel.call(Channel.java:1000)
16:49:59        at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler.execute(RemoteGitImpl.java:143)
16:49:59        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
16:49:59        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
16:49:59        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
16:49:59        at java.base/java.lang.reflect.Method.invoke(Method.java:566)
16:49:59        at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler.invoke(RemoteGitImpl.java:129)
16:49:59        at com.sun.proxy.$Proxy170.execute(Unknown Source)
16:49:59        at hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:1229)
16:49:59        at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1312)
16:49:59        at hudson.scm.SCM.checkout(SCM.java:540)
16:49:59        at hudson.model.AbstractProject.checkout(AbstractProject.java:1239)
16:49:59        at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:647)
16:49:59        at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:85)
16:49:59        at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:519)
16:49:59        at hudson.model.Run.execute(Run.java:1899)
16:49:59        at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:44)
16:49:59        at hudson.model.ResourceController.execute(ResourceController.java:107)
16:49:59        at hudson.model.Executor.run(Executor.java:449)
16:49:59 ERROR: Error cloning remote repo 'origin'
16:49:59 Finished: FAILURE

解决办法

  • 修正仓库路径格式:Windows下的Git不识别Linux风格的/mnt/h/GIT_NEW路径,需改为Windows兼容格式。若网络驱动器在Windows代理上映射为Z盘,使用file:///Z:/GIT_NEW;若为共享目录,使用file:////servername/sharename/GIT_NEW格式。
  • 确认代理端的网络驱动器挂载:网络驱动器需挂载在Windows代理机器上,而非Docker容器内。之前将驱动器挂载到Docker容器的/mnt/h/,但构建任务由Windows代理执行,代理无法识别该路径,需在Windows代理上把目标网络共享映射成本地盘符。
  • 使用UNC路径替代盘符:若映射盘符存在权限或识别问题,直接使用UNC路径\\server\share\GIT_NEW,Windows下的Git可正确解析该格式。
  • 调整Git配置(可选):若路径过长,在Windows代理的Git中执行git config --global core.longpaths true开启长路径支持;若存在换行符干扰,可设置git config --global core.autocrlf false。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.15 22:40:30