Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting git private repository project on jenkins server

I am trying to set git private repo on jenkins server. I have installed git plugin and also github. when I set repo url in jenkins project ui the error is

Failed to connect to repository : Command "git -c core.askpass=true 
ls-remote -h [email protected]:repo/project.git HEAD" returned 
status code 128:
stdout:
stderr: Permission denied (publickey).
fatal: The remote end hung up unexpectedl

What I have done up to now:

  1. My server user and jenkin user( both are in same server) are different. Though it seems to me these are not related. jenkins user are given all credintial.

  2. In my server under var/lib/jenkins/.ssh(.ssh is created by me) I added ssh key . Public key is added to github repo.

  3. By swithcting user to jenkins i can clone the project by this ssh. So i think there is not any public key adding problem.

I have googled the problem. there are many solutions. I tried most of them. But still no solution. Probably I am missing something.

My repo url is something like this [email protected]:repo/project.git

like image 927
Sazzad Avatar asked Feb 03 '15 07:02

Sazzad


2 Answers

If your HOME set in /var/lib/jenkins/ then i hope all the step you have been done successfully :)

Then one thing may be happen for your case. Like when you switch the user by using:

su jenkins 

This command means that you switch the user but the home directory will be same as a root's home!

So you need to switch user by confirming the specific user home also switched. TO doing so, you need to follow:

su -s /bin/bash jenkins

Then you need to generate either the ssh public key once again or just update the known host. This will work.

Related Link

like image 149
Naim Rajiv Avatar answered Nov 04 '22 14:11

Naim Rajiv


It depends on what HOME is set to when Jenkins is running: git will look for the ssh (public and private) keys under $HOME/.ssh.

Simply add a build step with an echo $HOME, and make sure your .ssh is in that folder.

like image 30
VonC Avatar answered Nov 04 '22 14:11

VonC