在 Jenkins 作业中如何调试“无法运行程序'C:\ Program Files \ Git'”?

7
我正在使用Jenkins构建我的Git项目,在查看日志时出现了以下错误。我在Jenkins中使用了Git插件。
您会如何解决此错误消息?
Started by user anonymous
Building in workspace E:\sw\jenkins\workspace\se12
ERROR: Workspace has a .git repository, but it appears to be corrupt.
hudson.plugins.git.GitException: Error performing command: git rev-parse --is-inside-work-tree

org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1180)
org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1150)
org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1146)
org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommand(CliGitAPIImpl.java:962)
org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommand(CliGitAPIImpl.java:972)
hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:651)
        at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:88)
    Caused by: java.io.IOException: Cannot run program "C:\Program Files\Git" (in directory "E:\sw\jenkins\workspace\se12"): CreateProcess error=5, Access is denied
        at java.lang.ProcessBuilder.start(Unknown Source)
        at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1169)
        ... 16 more
    Caused by: java.io.IOException: CreateProcess error=5, Access is denied
        at java.lang.ProcessImpl.create(Native Method)
        at java.lang.ProcessImpl.<init>(Unknown Source)
        at java.lang.ProcessImpl.start(Unknown Source)
        ... 22 more
    Cloning the remote Git repository
    Cloning repository $ git clone \\SE12\Adempiere370new\.git
    Fetching upstream changes from $ git clone \\SE12\Adempiere370new\.git
    ERROR: Error cloning remote repo 'origin'
    hudson.plugins.git.GitException: Error performing command: git fetch --tags --progress $ git clone \\SE12\Adempiere370new\.git +refs/heads/*:refs/remotes/origin/*
org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1180)
org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:1043)
hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:651)
        at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:88)

    Caused by: java.io.IOException: Cannot run program "C:\Program Files\Git" (in directory "E:\sw\jenkins\workspace\se12"): CreateProcess error=5, Access is denied
org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1169)
        ... 14 more
3个回答

11

可能你错误地设置了git可执行文件的路径。

它不应该是C:\Program Files\Git,而应该是C:\Program Files\Git\bin\git.exe
(这与JENKINS-6181类似)

Git插件页面确实提到:

如果您看到指示Git无法克隆的输出,类似于下面的输出,请转至Jenkins配置设置(不是项目设置,而是全局设置)并将Git路径更改为完全合格的路径(例如,不是“git”,而是“/usr/bin/git”或您安装Git二进制文件的位置)。

在您的情况下,请检查C:\Program Files\Git是否确实是您的Git安装路径。


以上答案很有帮助。但是“看起来不像是git仓库”的问题仍然存在。 - Tony Davis
@user3093983 那是另一个你需要提出的问题。 - VonC

1
在您的日志中,看起来Jenkins代理没有足够的权限执行Git。
hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:651)
        at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:88)
    Caused by: java.io.IOException: Cannot run program "C:\Program Files\Git" (in directory "E:\sw\jenkins\workspace\se12"): CreateProcess error=5, Access is denied

细节到
CreateProcess error=5, Access is denied

对我而言,问题不同,是:

对我来说问题不同,它是

CreateProcess error=2, The system cannot find the file specified

我做了一些研究,发现了这个问题 https://issues.jenkins.io/browse/JENKINS-12353

在底部有一个人说,在Windows中默认的PATH配置指向

C:\Program Files\Git\cmd

当它应该是这样的。
C:\Program Files\Git\bin

由于我在远程机器上拥有Jenkins代理,因此我不得不重新启动我的代理以重新加载主机中的PATH更改。


0

如果您正确知道git路径,则只需在URL中提及git.exe的路径,否则请提及“git”。当它执行时,它会检查jenkin服务器PATH环境变量,并在其中一个路径中找到git本身。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接