Jenkins(Windows Server 2025)在从流水线A 调用流水线B 时不会克隆共享库

编程语言 2026-07-09

我在Windows Server 2025上把Jenkins作为服务运行。

我的Jenkinsfiles与我的共享库也存放在同一个GitLab仓库中。

手动构建任意一个流水线时一切正常,但当流水线A 调用流水线B 时,会出现如下错误:

Started by upstream project "Test" build number 14
originally caused by:
 Started by user <UserName>
Loading library SharedLibTest@dev:libraries/
Attempting to resolve dev from remote references...
 > git.exe --version # timeout=10
 > git --version # 'git version 2.53.0.windows.2'
using GIT_ASKPASS to set credentials Jenkins token for GitLab access
 > git.exe ls-remote -h -- https://giturl/repo.git # timeout=10
Found match: refs/heads/dev revision b3efb5fbde73a1214ab44ff36dfc88b23a0217d6
Selected Git installation does not exist. Using Default
The recommended git tool is: NONE
using credential JenkinsGitLabToken
 > git.exe rev-parse --resolve-git-dir D:\h\workspace\RP@libs\4566a0d73a56c847d87178169741ab8291c61f3aad83825fd5ff8f285cbda243\.git # timeout=10
ERROR: Workspace has a .git repository, but it appears to be corrupt.
hudson.plugins.git.GitException: Error performing git command: git.exe rev-parse --resolve-git-dir D:\h\workspace\RP@libs\4566a0d73a56c847d87178169741ab8291c61f3aad83825fd5ff8f285cbda243\.git
    at PluginClassLoader for git-client//org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2864)
    at PluginClassLoader for git-client//org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2773)
    at PluginClassLoader for git-client//org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2768)
    at PluginClassLoader for git-client//org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommand(CliGitAPIImpl.java:2055)
    at PluginClassLoader for git-client//org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommand(CliGitAPIImpl.java:2067)
    at PluginClassLoader for git-client//org.jenkinsci.plugins.gitclient.CliGitAPIImpl.hasGitRepo(CliGitAPIImpl.java:407)
    at PluginClassLoader for git-client//hudson.plugins.git.GitAPI.hasGitRepo(GitAPI.java:283)
    at PluginClassLoader for git//hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:1205)
    at PluginClassLoader for git//hudson.plugins.git.GitSCM._checkout(GitSCM.java:1310)
    at PluginClassLoader for git//hudson.plugins.git.GitSCM.checkout(GitSCM.java:1277)
    at PluginClassLoader for workflow-scm-step//org.jenkinsci.plugins.workflow.steps.scm.SCMStep.checkout(SCMStep.java:136)
    at PluginClassLoader for pipeline-groovy-lib//org.jenkinsci.plugins.workflow.libs.SCMBasedRetriever.lambda$doRetrieve$4(SCMBasedRetriever.java:200)
    at PluginClassLoader for pipeline-groovy-lib//org.jenkinsci.plugins.workflow.libs.SCMBasedRetriever.retrySCMOperation(SCMBasedRetriever.java:222)
    at PluginClassLoader for pipeline-groovy-lib//org.jenkinsci.plugins.workflow.libs.SCMBasedRetriever.doRetrieve(SCMBasedRetriever.java:199)
    at PluginClassLoader for pipeline-groovy-lib//org.jenkinsci.plugins.workflow.libs.SCMSourceRetriever.retrieve(SCMSourceRetriever.java:79)
    at PluginClassLoader for pipeline-groovy-lib//org.jenkinsci.plugins.workflow.libs.LibraryAdder.retrieve(LibraryAdder.java:297)
    at PluginClassLoader for pipeline-groovy-lib//org.jenkinsci.plugins.workflow.libs.LibraryAdder.add(LibraryAdder.java:156)
    at PluginClassLoader for pipeline-groovy-lib//org.jenkinsci.plugins.workflow.libs.LibraryDecorator$1.call(LibraryDecorator.java:125)
    at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1087)
    at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:624)
    at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:602)
    at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:579)
    at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:323)
    at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:293)
    at PluginClassLoader for script-security//org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.GroovySandbox$Scope.parse(GroovySandbox.java:162)
    at PluginClassLoader for workflow-cps//org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.doParse(CpsGroovyShell.java:202)
    at PluginClassLoader for workflow-cps//org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.reparse(CpsGroovyShell.java:186)
    at PluginClassLoader for workflow-cps//org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.parseScript(CpsFlowExecution.java:670)
    at PluginClassLoader for workflow-cps//org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.start(CpsFlowExecution.java:616)
    at PluginClassLoader for workflow-job//org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:344)
    at hudson.model.ResourceController.execute(ResourceController.java:97)
    at hudson.model.Executor.run(Executor.java:456)
Caused by: java.io.IOException: Cannot run program "git.exe" (in directory "D:\h\workspace\RP@libs\4566a0d73a56c847d87178169741ab8291c61f3aad83825fd5ff8f285cbda243"): CreateProcess error=87, The parameter is incorrect

如果手动执行git命令,我没有看到任何错误。

在网上查找后,我尝试了以下解决方案:

  • 在HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem中启用Windows长路径
  • 为Git启用长路径(core.longpaths=true)
  • 将Jenkins的 home目录移动到驱动器根目录以缩短路径
  • 将流水线移动到Jenkins根目录(无子文件夹)以缩短路径

尽管做了这些改动,问题仍然存在。

Jenkins版本:2.555.1(最新)

Git插件版本:5.10.1(最新)

解决方案

最终通过在Jenkins工具中添加JGit找到了一个解决方案:

在Manage Jenkins > Tools > Git installations > + Add Git > JGit中添加JGit。

JGit是纯Java,因此Jenkins不需要运行Git.exe。

注:如果你使用带有遗留SCM的共享库,你需要在库定义中强制使用JGit(Manage Jenkins > System)。

站内所有文章版权归属LeftHeroAI导航站,无授权禁止任何主体转载、抄袭、复制内容,亦不得私自架设镜像站点。一经侵权,本站将通过法律途径追责。

相关文章