Jenkins 的 git 插件无法从本地机器克隆存储库。错误代码 128

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17307938/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 08:40:49  来源:igfitidea点击:

git plugin for Jenkins fails to clone a repo from local machine. Error code 128

gitjenkinsjenkins-plugins

提问by Vikram

Error:

错误:

Failed to connect to repository : Command "/usr/bin/git ls-remote -h file:///home/myuser/path/to/project HEAD" returned status code 128:
stdout:
stderr: fatal: 'home/myuser/path/to/project' does not appear to be a git repository
fatal: The remote end hung up unexpectedly

I have tried the following:

我尝试了以下方法:

  • chmod 777to the repo folder(folder containing .git directory)
  • chownedto jenkins:jenkinson the repo folder
  • tried to clone into another folder from this local repo folder: this works!
  • chmod 777到 repo 文件夹(包含 .git 目录的文件夹)
  • chownedjenkins:jenkins在回购文件夹
  • 试图从这个本地 repo 文件夹克隆到另一个文件夹:这有效!

When I run the above command: /usr/bin/git ls-remote -h file:///home/myuser/path/to/project HEADon cmd I get the branches.

当我运行上面的命令时:/usr/bin/git ls-remote -h file:///home/myuser/path/to/project HEAD在 cmd 上我得到了分支。

My questions are:

我的问题是:

  1. why is git ls-remote -h ...command called when it should be git clone ...?
  2. How to configure jenkins git plugin to fetch code from local repo
  1. 为什么git ls-remote -h ...在应该调用命令时调用命令git clone ...
  2. 如何配置 jenkins git 插件以从本地仓库获取代码

My environment:

我的环境:

RHEL 5.9

RHEL 5.9

Jenkins 1.519 installed as a service(no Web container)

Jenkins 1.519 作为服务安装(无 Web 容器)

Git plugin

Git插件

回答by Vikram

When installing Jenkinsas a service, by default, Jenkinsdoes not create a user directory as in: /home/jenkins. Jenkins default home directory is set to /var/lib/jenkins. From my work-around, as you would expect, jenkinshas trouble accessing local resources from other users directory.

Jenkins作为服务安装时,默认情况下Jenkins不会创建用户目录,如:/home/jenkins。Jenkins 默认主目录设置为/var/lib/jenkins. 正如您所料,从我的解决方法来看,jenkins从其他用户目录访问本地资源时遇到问题。

I moved my cloned repo under Jenkins default home directory i.e. under /var/lib/jenkinsso my Repository URLin Jenkins Project configuration looks like: file:///${JENKINS_HOME}/repo/<myprojectname>

我将克隆的存储库移动到 Jenkins 默认主目录下/var/lib/jenkins,即Repository URL在 Jenkins 项目配置下,如下所示:file:///${JENKINS_HOME}/repo/<myprojectname>

UPDATE:The above works fine ...but I found a better way to do it from this blog

更新:以上工作正常......但我从这个博客中找到了一个更好的方法

The steps are outlined here:

此处概述了这些步骤:

look up /etc/init.d/jenkinsscript. There are a few $JENKINSvariables defined . This should lead you to the sysconfigfor jenkins i.e. /etc/sysconfig/jenkins. Stop your jenkins instance:

查找/etc/init.d/jenkins脚本。$JENKINS定义了几个变量。这应该会引导您进入sysconfigfor jenkins ie /etc/sysconfig/jenkins。停止你的詹金斯实例:

sudo /sbin/service jenkins stop

sudo /sbin/service jenkins stop

Take a backup

进行备份

cp /etc/sysconfig/jenkins /etc/sysconfig/jenkins.bak

cp /etc/sysconfig/jenkins /etc/sysconfig/jenkins.bak

In this file, change the following property:

在此文件中,更改以下属性:

$JENKINS_USER="<your desired user>"

$JENKINS_USER="<your desired user>"

Change ownership of all related Jenkins directories:

更改所有相关 Jenkins 目录的所有权:

chown -R <your desired user>:<your user group> /var/lib/jenkins

chown -R <your desired user>:<your user group> /var/lib/jenkins

chown -R <your desired user>:<your user group> /var/cache/jenkins

chown -R <your desired user>:<your user group> /var/cache/jenkins

chown -R <your desired user>:<your user group> /var/log/jenkins

chown -R <your desired user>:<your user group> /var/log/jenkins

Restart jenkins and that error should disappear

重新启动詹金斯,该错误应该消失

sudo /sbin/service jenkins start

sudo /sbin/service jenkins start

This error should go away now!

这个错误现在应该消失了!

回答by Bulba

It's been a while since this question was asked, but I had this problem today and there are very few resources. Most probably, because people tend to connect to git repositories remotely.

问这个问题已经有一段时间了,但我今天遇到了这个问题,而且资源很少。很可能是因为人们倾向于远程连接到 git 存储库。

I checked using strace what exactly jenkins was doing and yes, it was a problem with permissions.

我使用 strace 检查了 jenkins 到底在做什么,是的,这是权限问题。

But I solved it in a simpler way than answer #2 - by adding jenkins to the git server group - in my case, git1: root# gpasswd -a jenkins git1 root# service jenkins restart

但是我用比答案 #2 更简单的方式解决了它 - 通过将 jenkins 添加到 git 服务器组 - 在我的情况下,git1: root# gpasswd -a jenkins git1 root# service jenkins restart

回答by Greg Burghardt

I'm running Jenkins on Windows and had the same problem. I was able to solve this by having the Jenkins service log in as my user on my laptop.

我在 Windows 上运行 Jenkins 并且遇到了同样的问题。我能够通过让 Jenkins 服务以我的笔记本电脑上的用户身份登录来解决这个问题。

(Windows 7)

(Windows 7的)

  1. Open Task Manager (Ctrl + Shift + Escape)
    1. (Windows 10 only) Click on More Detailsin the lower left corner of the pop up window
  2. Go to the Servicestab
  3. Click the Services...button
  4. Find "Jenkins" in the list of services
  5. Right-click "Jenkins" and click on Properties
  6. Click the Log Ontab in the Jenkins Propertieswindow
  7. Choose This account:under Log on as:
  8. Enter your username and password
  9. Click OK
  10. Restart the Jenkins service
  11. Then Bob's your uncle.
  1. 打开任务管理器(Ctrl + Shift + Escape)
    1. (仅限 Windows 10)点击More Details弹出窗口左下角的
  2. 转到服务选项卡
  3. 点击Services...按钮
  4. 在服务列表中找到“Jenkins”
  5. 右键单击“Jenkins”并单击“属性”
  6. 单击Jenkins 属性窗口中的登录选项卡
  7. 选择此帐户:登录身份下:
  8. 输入你的用户名与密码
  9. 点击 OK
  10. 重启詹金斯服务
  11. 那么鲍勃是你的叔叔。

回答by Mir S Mehdi

  1. Jenkins uses git clonecommand only for the first time when a workspace is configured for a project. Further instances uses the git ls-remotecommand.

  2. I had the same issue when I configured Jenkins. It was resolved by playing around with the SSH Keys. This looks like a configuration issue as well. Check if SSH Keys are setup for the Jenkins account.

  1. Jenkinsgit clone仅在第一次为项目配置工作区时使用命令。更多实例使用该git ls-remote命令。

  2. 我在配置 Jenkins 时遇到了同样的问题。它是通过使用 SSH 密钥解决的。这看起来也是一个配置问题。检查是否为 Jenkins 帐户设置了 SSH 密钥。

Also, see the step by step procedure of configuration of SSH in the link provided. This might not give you exact solution, but can point you to the solution.

此外,请参阅提供的链接中配置 SSH 的分步过程。这可能不会为您提供确切的解决方案,但可以为您指明解决方案。

http://oodlestechnologies.com/blogs/How-to-setup-Jenkins-With-Grails-on-Ubuntu

http://oodlestechnologies.com/blogs/How-to-setup-Jenkins-With-Grails-on-Ubuntu

回答by gilsaints88

I find that the other solutions are a bit "hacky" for me. What I did was move the Jenkins Home folder from /Users/Shared/ to /Users/[myacccount]/. This way, my Jenkins will have access to my repos and to my Android SDK (because that's where I use Jenkins for). Then change the JENKINS_HOME environment variable. I did this by entering the JENKINS_HOME in my .bash_profile (but there are other ways to do this).

我发现其他解决方案对我来说有点“hacky”。我所做的是将 Jenkins Home 文件夹从 /Users/Shared/ 移动到 /Users/[myacccount]/。这样,我的 Jenkins 将可以访问我的存储库和我的 Android SDK(因为那是我使用 Jenkins 的地方)。然后更改 JENKINS_HOME 环境变量。我通过在我的 .bash_profile 中输入 JENKINS_HOME 来做到这一点(但还有其他方法可以做到这一点)。

Note: I use OSX

注意:我使用 OSX

回答by xjcl

Instead of file:///you can also use ssh://as in this answer:

相反的file:///,你也可以用ssh://这个答案

ssh://YOUR_USER@localhost/PATH_TO_YOUR_PROJECT

Note that you need to do the standard ssh setup:

请注意,您需要进行标准的 ssh 设置:

  1. Generate a keypair using ssh-keygenif you don't already have one in ~/.ssh
  2. Paste private key (default ~/.ssh/id_rsa) into Jenkins (project settings, git repo, credentials)
  3. Paste public key into ~/.ssh/authorized_keys
  1. ssh-keygen如果您还没有,请使用生成一个密钥对~/.ssh
  2. 将私钥(默认~/.ssh/id_rsa)粘贴到 Jenkins(项目设置、git repo、凭据)中
  3. 将公钥粘贴到 ~/.ssh/authorized_keys