git - 如何从 git 添加 ssh key 到 Jenkins?

标签 git ubuntu jenkins ssh

我正在尝试在本地机器上设置新的 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/

相关文章:

带有 bup 的 git 附件

linux - 如何为 Wordpress 创建一个用户来执行 FTP 操作,并为其授予适当的权限?

curl - Jenkins 工作失败,无法从 curl 获得非 200 响应

git - Jenkins 管道构建 github pull 请求

linux - 如何更改 docker id 和名称

git - 为什么 git pull 会导致数以千计的 merge 冲突?

git - git 的大文件扩展

ubuntu - 在 Ubuntu 上安装的 dotnet 运行时在哪里?

ubuntu - 限制 Docker 容器上的内存不起作用

jenkins - 如何在 Jenkins 中设置 "Resource root URL"