1

I'm trying to setup new jenkins project on local machine, I have added bitbucket repo in Source Code Management section under Git Repositories

But I get an error:

Failed to connect to repository : Command "git ls-remote -h ssh://git@<main_link>/<name1>/<name2>.git HEAD" returned status code 128:
stdout:
stderr: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

Howewer I can run this command from my console (also I can do git clone etc.)

I tried to add ssh key via Add Credentials with option Private Key - Enter directly

As I understand my private key is under ~/.ssh/

ls ~/.ssh/
cat ~/.ssh/id_dsa

but after I have entered private ssh key from ~/.ssh/id_dsa nothing changed, I still get the error.

Update: Tried this answer: https://stackoverflow.com/a/15314910/1179925

sudo -i -u jenkins
jenkins@user-VirtualBox:~$ git clone ssh://git@<link>/<name1>/<name2>.git
Cloning into '<name2>'...
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
Community
  • 1
  • 1
mrgloom
  • 20,061
  • 36
  • 171
  • 301

2 Answers2

0

Make sure Jenkins is running with your account (or its %HOME%/.ssh would not be yours)

Also, you can reference your private key with the SSH Jenkins Credential plugin (based on Jenkins Credential Plugin), and use that credential (ie that specific private key) in your Jenkins job setting.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
0

Solution is following:

#Switch to jenkins user
sudo -i -u jenkins

#Get public key
cat ~/.ssh/id_rsa.pub

#Add public key for jenkins in github\bitbucket web interface.

not sure on which step jenkins generate it's key, but in my case it was already there.

mrgloom
  • 20,061
  • 36
  • 171
  • 301