24

I need some help here, It's been a week I'm with this problem, can't figure out what's going on. I'm not able to clone a git repo from a slave node (Jenkins). I added the ssh key, host and slave (I've already tried generating a single key and one for each virtual and host)).

On Jenkins:

  • url:git@github.com: < repo>
  • Credentials: Here I tried with username/password, username with ssh file, username with ssh key directly, and -none-.

It doesn't seems like there is an authentication problem since I can clone the repo manually from console (both, slave and host). I can also connect with

ssh -T git@github.com

so the ssh key is fine, but when I build, this appear on console:

Building remotely on IE10Win7 in workspace C:\Users\IEUser\Desktop\< folder >

Wiping out workspace first.

Cloning the remote Git repository

Cloning repository git@github.com:< repo>.git

git init C:\Users\IEUser\Desktop\< folder> # timeout=10

ERROR: Error cloning remote repo 'origin'

ERROR: Error cloning remote repo 'origin'

Performing Post build task...

Does anyone have an idea? Hope someone can give me a clue, Thanks!

Nicolas Amabile
  • 241
  • 1
  • 2
  • 5
  • I'm sorry I can't offer any help, but I'm definitely also looking forward to any input on this. I have the same problem on a Windows 7 (64) master trying to connect to a private repo. One job can not connect at all (with the above error), others all the time without problems, a few experience the error arbtrarily. – Sir Jane Apr 16 '15 at 11:33
  • I know this isn't a typical answer, but I had goofed and my builds were going to slave with incorrect credentials. Anyway, my $0.02 is to try it on another known good slave if these other solutions are falling short. – kayleeFrye_onDeck Sep 20 '16 at 22:54

8 Answers8

22

I fixed this problem by setting the slave node tool path, selecting git and setting its value to

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

Location: Configure Node - Tool Locations

joe_young
  • 3,888
  • 2
  • 22
  • 35
starlying
  • 221
  • 2
  • 3
11

I recently updated several jenkins plugins and had this problem after the updates. Rolling back the git plugin didn't help, but I did a few other things to get it working. I listed all three here, but it was probably (2) that fixed the problem. Apparently the git executable was reset to default. So, configuring the git executable within the specific project was probably all that was needed. However the other items might come in handy too.

(1) The default git on a jenkins linux install geenrally points to /usr/lib... You need to specify a separate GitForWindows that points to the windows version:

Manage Jenkins
Configure System
Under Git - Git Installations
    Add Git -> Git
    Give it a name to be referenced in projects
      (mine is WindowsGit)
    Set Path to Git Executable
      (mine is "C:\Program Files (x86)\Git\bin\git.exe")
      (for recent git the path is "C:\Program Files\Git\bin\git.exe")

(2) Configure git on the specific project:

Select the project
Select Configure
Under Source Code Management - Git
    Select Git Executable as configured in 1)
    Set credentials or add new (ssh keys, etc)

(3) Updating the jenkins slave service to run as a specific user:

Go to Windows Services on the slave -- StartMenu, type "services"
Select the Jenkins Slave service in the list on the right
Right-click and select "Properties" of the Jenkins Slave service
Select the "Log On" tab
Update the username and password used in manual tests
    Domain login can be specificied with <DOMAIN>\<USERNAME>
    Local logins just use <USERNAME>
OK to save and exit
Right-click again and select "Restart" to make the changes active.
dhj
  • 465
  • 5
  • 16
  • 3
    I've followed the three steps, only after setting administrator rights on the jenkisn service it started working. – andyroschy Oct 23 '15 at 17:03
4

I found a decent workaround in my case. The git clone command always inherits its process owner, which may make a difference, even if the two owners of Jenkins (SYSTEM) and cmd (USER) seem to have the same rights on your system. All other configurations were identical (keys, knownhosts, Git client version).

So as far as I can see, calling git clone from cmd will succeed because it calls the remote as USER, whereas git clone called from Jenkins may be rejected because it calls the remote as SYSTEM. In Services, where you would typically start Jenkins through the GUI, you can configure the service to run as a different user (right click on service --> Properties --> Log On). I had to put it like USER@DOMAIN, e.g. Jenkins@company.local or so. I'm not sure about how a cmd parameter would look, but I'd expect there to be one.

Also, I don't quite know what difference this workaround makes in the end, because on my Jenkins, SYSTEM and USER are configured to have the same rights across the system and they are of course both recognized as "Jenkins" by remote. Still, it does the trick for me. Deeper insights welcome.

Sir Jane
  • 232
  • 2
  • 12
  • The same thing happened to me again when I set up another Windows slave. It started after I installed the slave as a service ... That changes the user to SYSTEM. But I actually forgot that I had already put this answer here months ago, so I searched and wondered all over again x) – Sir Jane Dec 22 '15 at 10:08
0

I was facing similar problem and found that I need to add git to my PATH environment variable for a Windows based slave. I think that @dhj suggestion 2 might work as well in this case.

I found this workaround on Jenkins Jira.

sttaq
  • 1,603
  • 2
  • 20
  • 38
0

In my case, I started getting this exact error after updating Git on some of my build machines (via Chocolatey, using the "git.install" package) from 1.9.4 to 2.5.0. The old 1.9.4 install was a 32-bit package but the new one is a 64-bit one, so the default install location switched from C:\Program Files (x86)\Git to C:\Program Files\Git. I had the 64-bit path configured on the Jenkins master (since it had the newer Git version), but some slaves still had the older 32-bit version installed, so the slaves were attempting to use an incorrect path. I could have overridden the Git path for individual slaves but the cleaner solution for me was simply to upgrade all the slaves to the newer 64-bit version.

Nick Jones
  • 4,235
  • 5
  • 31
  • 43
0

I tried most of the above:

Specify git location. Set service user. Run as Administrator.

None of it worked. Eventually decided to uninstall git64 and install git32... changed the git path to the new location (in x86 Program Files). And everything worked.

Trev M
  • 26
  • 2
0

I ran into this issue recently.

We had some items in our PATH EV which we had added when trying to connect Winium and Selenium to our Jenkins instance.

We removed these items, but still Jenkins seemed to be holding on to the values. After a bit of troubleshooting: restarting Jenkins; restarting the Jenkins server; setting the EVs at the node level; etc., we restarted the Jenkins JNLP service on the Windows slave.

And they lived happily ever after.

Chris Giddings
  • 607
  • 1
  • 7
  • 18
0

I also got the same error and fixed by adding a git path in the "Manage Jenkins -> Global Tool Configuration".

In my env, The windows Jenkins master run a job on the ubuntu slave machine, the master machine has used the default git ('C:\Program Files\Git\git.exe') path and the slave machine has used the git ('/usr/bin/git') path, therefore, I configured slave git path into the master configuration '/usr/bin/git' and its start working for me

Naren Chejara
  • 759
  • 7
  • 6