【问题标题】:How to add ssh key from git to Jenkins?如何将 ssh 密钥从 git 添加到 Jenkins?
【发布时间】:2016-12-26 16:00:46
【问题描述】:

我正在尝试在本地机器上设置新的 jenkins 项目,我在 Source Code Management 部分的 Git Repositories 下添加了 bitbucket 存储库

但我得到一个错误:

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 使用选项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.

【问题讨论】:

标签: git ubuntu jenkins ssh


【解决方案1】:

确保 Jenkins 使用您的帐户运行(否则其 %HOME%/.ssh 将不是您的)

此外,您可以使用 SSH Jenkins Credential plugin(基于 Jenkins Credential Plugin)引用您的私钥,并在您的 Jenkins 作业设置中使用该凭据(即该特定私钥)。

【讨论】:

    【解决方案2】:

    解决方法如下:

    #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 在哪一步生成它的密钥,但在我的情况下它已经存在了。

    【讨论】:

      猜你喜欢
      • 2018-03-15
      • 1970-01-01
      • 1970-01-01
      • 2021-06-23
      • 2011-03-11
      • 2020-01-12
      • 2013-09-14
      • 2020-06-21
      • 2017-01-30
      相关资源
      最近更新 更多