Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Authentication with Jenkins and Git

Tags:

git

jenkins

I would like to use Jenkins with a repository on Bitbucket. For that, I created a ssh key with the user jenkins and the command ssh-keygen -t rsa -C "my_email". I added the public key on Bitbucket and I can clone a project with git clone ....

But when I configure the project in Jenkins, I put the url [email protected]:my_username/my_repository.git

Here is the error :

Failed to connect to repository : Command "git ls-remote -h [email protected]:skurty/ma-carte-augmentee-bo.git HEAD" returned status code 128:

stdout: 

stderr: ssh_askpass: exec(/usr/bin/ssh-askpass): No such file or directory 
Permission denied (publickey).
fatal: The remote end hung up unexpectedly

If I do ssh [email protected], I get:

PTY allocation request failed on channel 0
conq: logged in as my_username.

You can use git or hg to connect to Bitbucket. Shell access is disabled.
Connection to bitbucket.org closed.

I also tried to create the file ~/.ssh/authorized_keys and put in it the public key, but same problem.

I also restarted jenkins with sudo /etc/init.d/jenkins restart

Thank you for your help :)

PS : I'm on a Debian Squeeze 64 bits

like image 988
skurty Avatar asked Mar 16 '13 13:03

skurty


3 Answers

The only way I found to make it work was removing the passphrase from my ssh keys. I guess the jenkins' git plugin was having trouble providing the passphrase, even when I set it in the advanced section of the Credentials plugin.

$ ssh-keygen -p

Provide the location of your private key, type your current passphrase and leave the new one empty.

like image 123
José Ricardo Avatar answered Nov 09 '22 02:11

José Ricardo


The problems comes from the fact that you NEVER logged in with user JENKINS on GIT

therefore, you should do the following :

log in JENKINS machine:

sudo su jenkins
ssh [email protected]

validate access.

Now you should be able to perform jenkins build with git

like image 3
aorfevre Avatar answered Nov 09 '22 02:11

aorfevre


Is the id_rsa or whatever your private key is called, in the jenkins user's home directory?

If you installed with a native package, the file should be located in /var/lib/jenkins/.ssh and the permissions for /var/lib/jenkins/.ssh should be 700 while the permissions of /var/lib/jenkins/.ssh/id_rsa should be 600

like image 1
R. Tyler Croy Avatar answered Nov 09 '22 02:11

R. Tyler Croy