我正在尝试在本地机器上设置新的 jenkins 项目,我在 Git Repositories
下的 Source Code Management
部分添加了 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.
但是我可以从我的控制台运行这个命令(我也可以做 git clone
等)
我尝试通过 Add Credentials
选项添加 ssh key Private Key - Enter directly
据我了解,我的私钥位于 ~/.ssh/
ls ~/.ssh/
cat ~/.ssh/id_dsa
但是在我从 ~/.ssh/id_dsa
输入私有(private) ssh key 后没有任何改变,我仍然得到错误。
更新: 试过这个答案: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.
最佳答案
确保 Jenkins 正在使用您的帐户运行(或者它的 %HOME%/.ssh
不会是您的)
此外,您可以使用 SSH Jenkins Credential plugin 引用您的私钥(基于 Jenkins Credential Plugin ),并在您的 Jenkins 作业设置中使用该凭证(即该特定私钥)。
关于git - 如何从 git 添加 ssh key 到 Jenkins?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41305895/