Jenkins 的 git 插件无法从本地机器克隆存储库.错误代码 128
错误:
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
我尝试了以下方法:
-
chmod 777
到repo文件夹(包含.git目录的文件夹) -
chowned
到 repo 文件夹上的jenkins:jenkins
- 试图从这个本地 repo 文件夹克隆到另一个文件夹:这是有效的!
-
chmod 777
to the repo folder(folder containing .git directory) -
chowned
tojenkins:jenkins
on the repo folder - tried to clone into another folder from this local repo folder: this works!
当我在 cmd 上运行上述命令时:/usr/bin/git ls-remote -h file:///home/myuser/path/to/project HEAD
我得到了分支.
When I run the above command: /usr/bin/git ls-remote -h file:///home/myuser/path/to/project HEAD
on cmd I get the branches.
我的问题是:
- 为什么
git ls-remote -h ...
命令应该在git clone ...
时调用? - 如何配置 jenkins git 插件以从本地仓库获取代码
- why is
git ls-remote -h ...
command called when it should begit clone ...
? - How to configure jenkins git plugin to fetch code from local repo
我的环境:
RHEL 5.9
Jenkins 1.519 作为服务安装(无 Web 容器)
Jenkins 1.519 installed as a service(no Web container)
当安装 Jenkins
作为服务时,默认情况下,Jenkins
不会像这样创建用户目录:/home/jenkins
.Jenkins 默认主目录设置为 /var/lib/jenkins
.正如您所料,根据我的解决方法,jenkins
无法从其他用户目录访问本地资源.
When installing Jenkins
as a service, by default, Jenkins
does 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, jenkins
has trouble accessing local resources from other users directory.
我将克隆的存储库移动到 Jenkins 默认主目录下,即 /var/lib/jenkins
下,因此我在 Jenkins 项目配置中的 Repository URL
如下所示:file:///${JENKINS_HOME}/repo/
I moved my cloned repo under Jenkins default home directory i.e. under /var/lib/jenkins
so my Repository URL
in Jenkins Project configuration looks like: file:///${JENKINS_HOME}/repo/<myprojectname>
更新:以上工作正常......但我从 这个博客
UPDATE: The above works fine ...but I found a better way to do it from this blog
此处概述了步骤:
查找 /etc/init.d/jenkins
脚本.定义了几个 $JENKINS
变量.这应该会引导您进入 jenkins 的 sysconfig
,即 /etc/sysconfig/jenkins
.停止您的 jenkins 实例:
look up /etc/init.d/jenkins
script. There are a few $JENKINS
variables defined
. This should lead you to the sysconfig
for jenkins i.e. /etc/sysconfig/jenkins
.
Stop your jenkins instance:
sudo/sbin/service jenkins stop
备份
cp/etc/sysconfig/jenkins/etc/sysconfig/jenkins.bak
在此文件中,更改以下属性:
In this file, change the following property:
$JENKINS_USER=""
更改所有相关 Jenkins 目录的所有权:
Change ownership of all related Jenkins directories:
chown -R :/var/lib/jenkins
chown -R :/var/cache/jenkins
chown -R :/var/log/jenkins
重新启动 jenkins,该错误应该会消失
Restart jenkins and that error should disappear
sudo/sbin/service jenkins start
这个错误现在应该消失了!
This error should go away now!