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 777
to the repo folder(folder containing .git directory) chowned
to jenkins:jenkins
on the repo folderWhen I run the above command: /usr/bin/git ls-remote -h file:///home/myuser/path/to/project HEAD
on cmd I get the branches.
My questions are:
git ls-remote -h ...
command called when it should be git clone ...
?My environment:
RHEL 5.9
Jenkins 1.519 installed as a service(no Web container)
Git plugin
The error that shows in this question indicates that Jenkins is trying to connect git-hub with the wrong ssh key. Log on to the Host machine of Jenkins and try to do clone but not on the Jenkins host. Try to ssh now, If it fails again then you need to add a proper key to /. ssh.
Configuring Git with Jenkins Now open your project and go to configure. Step 2: Give the repository Url in Source Code Management, repository Url can be fetched by clicking on clone and download option of Github and you have to select the SSH Url. Also, add credentials there of Jenkins.
From the branches dropdown click on the branch you need. You can view the dropdown here: Then copy the Github URL (Copy from the address bar) and paste it in VS studio. That's it.
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.
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
The steps are outlined here:
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
Take a backup
cp /etc/sysconfig/jenkins /etc/sysconfig/jenkins.bak
In this file, change the following property:
$JENKINS_USER="<your desired user>"
Change ownership of all related Jenkins directories:
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/log/jenkins
Restart jenkins and that error should disappear
sudo /sbin/service jenkins start
This error should go away now!
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.
I checked using strace what exactly jenkins was doing and yes, it was a problem with permissions.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With