Vikram
Vikram

Reputation: 4190

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

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:

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.

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

My environment:

RHEL 5.9

Jenkins 1.519 installed as a service(no Web container)

Git plugin

Upvotes: 22

Views: 25902

Answers (6)

xjcl
xjcl

Reputation: 15309

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

ssh://YOUR_USER@localhost/PATH_TO_YOUR_PROJECT

Note that you need to do the standard ssh setup:

  1. Generate a keypair using ssh-keygen if 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

Upvotes: 0

Greg Burghardt
Greg Burghardt

Reputation: 18783

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 7)

  1. Open Task Manager (Ctrl + Shift + Escape)
    1. (Windows 10 only) Click on More Details in the lower left corner of the pop up window
  2. Go to the Services tab
  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 On tab in the Jenkins Properties window
  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.

Upvotes: 6

gilsaints88
gilsaints88

Reputation: 1160

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).

Note: I use OSX

Upvotes: 0

Bulba
Bulba

Reputation: 835

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

Upvotes: 8

Vikram
Vikram

Reputation: 4190

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 URLin 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!

Upvotes: 25

Mir S Mehdi
Mir S Mehdi

Reputation: 1530

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

  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.

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.

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

Upvotes: 3

Related Questions