错误:克隆远程仓库'origin'时出错

29

尝试使用配置选项,无法找到工具配置选项和git可执行文件部分。似乎只在成功构建后才会发生这种情况。请帮忙。

在控制台输出部分构建项目后,这是我收到的输出:

  Building in workspace C:\Users\Anishas\.jenkins\workspace\Sample123
    Cloning the remote Git repository
    Cloning repository https://github.com/AnishaSalunkhe/HelloWorld.git
     > C:\Users\Anishas\git init C:\Users\Anishas\.jenkins\workspace\Sample123 # timeout=10
    ERROR: Error cloning remote repo 'origin'
    hudson.plugins.git.GitException: Could not init C:\Users\Anishas\.jenkins\workspace\Sample123
        at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$5.execute(CliGitAPIImpl.java:656)
        at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$2.execute(CliGitAPIImpl.java:463)
        at hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:1057)
        at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1097)
        at hudson.scm.SCM.checkout(SCM.java:485)
        at hudson.model.AbstractProject.checkout(AbstractProject.java:1269)
        at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:607)
        at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:86)
        at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:529)
        at hudson.model.Run.execute(Run.java:1738)
        at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
        at hudson.model.ResourceController.execute(ResourceController.java:98)
        at hudson.model.Executor.run(Executor.java:410)
    Caused by: hudson.plugins.git.GitException: Error performing command: C:\Users\Anishas\git init C:\Users\Anishas\.jenkins\workspace\Sample123
        at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1726)
        at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1695)
        at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1691)
        at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommand(CliGitAPIImpl.java:1321)
        at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$5.execute(CliGitAPIImpl.java:654)
        ... 12 more
    Caused by: java.io.IOException: Cannot run program "C:\Users\Anishas\git" (in directory "C:\Users\Anishas\.jenkins\workspace\Sample123"): CreateProcess error=5, Access is denied
        at java.lang.ProcessBuilder.start(Unknown Source)
        at hudson.Proc$LocalProc.<init>(Proc.java:240)
        at hudson.Proc$LocalProc.<init>(Proc.java:212)
        at hudson.Launcher$LocalLauncher.launch(Launcher.java:815)
        at hudson.Launcher$ProcStarter.start(Launcher.java:381)
        at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1715)
        ... 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
    ERROR: null
    Finished: FAILURE
16个回答

55

这在我的 Jenkins Windows 从机上浪费了太多时间。

我知道 git 在路径中,因为我在构建作业的批处理命令中执行了 "where git" 命令。

where git
C:\Program Files (x86)\Git\cmd\git.exe

显然,Jenkins Git插件在继承环境之前执行**。

将你的从节点路径设置为Git(就这样吧!!)

1)进入Windows从节点配置 管理Jenkins > 管理节点

2)选择您的从节点配置

3)在节点属性下检查工具位置

4)输入完整的git可执行文件路径,包括git.exe

[x] Tool Locations
   Name: (GIT) git
   Home: C:\Program Files (x86)\Git\cmd\git.exe

请查看屏幕截图:

enter image description here


7
我的天啊,太感谢了。 - b15
2
如何将Linux作为从机?/usr/bin/git无法工作。 - Abhilash Mishra
3
我尝试过这个,但对我没有用。仍然面临相同的问题。 - Sumith08
你节省了我的精力。感谢您发布正确的解决方案。 - Mohit M
1
使用 /usr/bin/git 作为 Linux 构建从机对我很有效。 - rhavelka
很奇怪的是标签是“Home”,但你必须包含git.exe(在Windows上)。 “Home”似乎暗示了一个目录位置,但在这种情况下并非如此。 一旦我添加了git.exe部分,我的流水线就按预期开始工作了。 - StvnBrkdll

18

前往管理Jenkins / 全局工具配置并设置Git可执行文件路径

在此输入图片描述


4

将路径设置为git.exe而不仅仅是工具配置中git文件的目录,这两个位置都需要进行设置。


我浪费了将近一天的时间才找到这个评论!谢谢。 - Rvy Pandey
1
@RvyPandey 你怎么理解他在说什么?我读了五遍,还是不明白。 - MiDaa
2
@MiDaa,我知道如果你直接阅读这个答案,可能很难理解。但是如果你阅读整个帖子(所有答案),你也会明白的。他的意思是,在Jenkins > 全局工具配置 > Git > git可执行文件路径中,设置你的工具路径为C:\Program Files\Git\bin\git.exe,而不仅仅是C:\Program Files\Git\bin(或者你系统上其他路径)。 还有其他的答案也建议这么做,但是对我来说,这个回答非常直观易懂。 - Rvy Pandey
1
@RvyPandey 谢谢,我通过在管道命令中设置gittool另外解决了它。 - MiDaa

4
  1. 在 Linux 环境的 Jenkins 服务器上检查以下命令:
`whereis git`

你将获得类似 /usr/bin/git 的路径

  1. 将其放置在“管理Jenkins>全局工具配置”下的git路径中,指定为 /usr/bin/git

  2. 重新运行作业


3
有时候,当磁盘空间不足时会出现此错误。因此,请检查您托管 jenkins 的机器的空间情况。 :)

1
这可以作为一个注释添加,而不是一个答案,看起来OP已经解决了问题。 - nj2237

2

如果有人正在使用全新安装的Xcode作为Jenkins的构建环境,那么您需要使用sudo xcodebuild -license命令同意许可证,或通过UI界面进行同意。


2

这可能有多个原因:

  1. 检查文件夹或工作节点的权限,在我的情况下,第三个问题是由于未为用户和组提供权限。因此,您可能需要执行以下操作:sudo chown -R user:group folderName
  2. 检查是否已配置SSH密钥,如果您正在使用GitHub的私有存储库。
  3. 必须在Jenkins全局配置的默认Git中提供路径。

我遇到了权限问题。 - Sergey Pleshakov

2
在我的情况下,我已经在我的从服务器上安装了git。请下载git并运行以下命令:

where git

将输出exe文件的路径。在Jenkins节点配置中更新你的git路径,如下所示:

C:\Program Files\Git\cmd\git.exe

前往Windows从属配置,管理Jenkins > 管理节点 > 选择你的从属 > 配置
在“节点属性”下检查“工具位置”,并给出你从'where git'命令中得到的完整路径,然后保存。

2

我在Linux ec2实例上遇到了相同的问题,但是我通过以下方法解决了它:

  1. 首先,在您的服务器上运行以下命令,该命令将返回给您 $ which git 此命令将向您返回git的实际路径,即安装git的位置,例如 /usr/bin/git,请复制此路径。
  2. 打开Jenkins > 转到管理Jenkins > 全局工具配置 > 将此字段中的内容粘贴进去 "Path to Git executable you can see in the image

1

1)确保git.exe具有可执行权限。 2)确保在全局工具配置中和Jenkins代理(在您的情况下为Windows)中正确配置git,并且在运行作业的环境变量中设置了git.exe可执行文件的正确值。


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