我正在尝试在本地计算机上设置新的jenkins项目,我在Source Code Management
Git Repositories
部分添加了bitbucket repo
但是我收到了一个错误:
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我可以从我的控制台运行此命令(我也可以git clone
等)。
我尝试使用选项Add Credentials
Private Key - Enter directly
添加ssh密钥
据我所知,我的私钥位于~/.ssh/
ls ~/.ssh/
cat ~/.ssh/id_dsa
但在我从~/.ssh/id_dsa
输入私人ssh密钥后没有任何变化,我仍然收到错误。
更新 试过这个答案: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.
答案 0 :(得分:0)
确保Jenkins与您的帐户一起运行(或%HOME%/.ssh
不属于您的帐户)
此外,您可以使用SSH Jenkins Credential plugin(基于Jenkins Credential Plugin)引用您的私钥,并在Jenkins作业设置中使用该凭据(即该特定私钥)。
答案 1 :(得分:0)
解决方案如下:
#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.
不确定jenkins在哪一步生成它的关键,但就我而言,它已经存在了。