【问题标题】:error 128 when trying to clone a git repository using jenkins尝试使用 jenkins 克隆 git 存储库时出现错误 128
【发布时间】:2019-03-31 16:03:59
【问题描述】:

我可以在托管 Jenkins 应用程序的 Linux 服务器上克隆我的 git 存储库,但是当我尝试创建一个新的 Jenkins 作业来执行此操作时,我收到错误 128。

“无法连接到存储库:命令“git ls-remote -h ssh://git@bitbucket.org/user/proj.git HEAD”返回状态码 128: 标准输出: 标准错误:权限被拒绝(公钥)。 致命:无法从远程存储库读取。

请确保您拥有正确的访问权限 并且存储库存在。”

我做过的事情

  1. 在 Linux 服务器上安装 git。

  2. 安装 BitBucket 插件及其对 Jenkins 应用的依赖项。

  3. 创建 SSH 密钥。

  4. 将密钥导入 BitBucket 和 Jenkins 文件夹。
  5. 为 Jenkins 用户设置 SSH 密钥的权限。
  6. 我在 Jenkins 应用上创建了 SSH 凭据。

在终端上工作

bash-4.2$ bash-4.2$ whoami jenkins bash-4.2$ ssh -T git@bitbucket.org authenticated via a deploy key. You can use git or hg to connect to Bitbucket. Shell access is disabled. This deploy key has read access to the following repositories: user/proj: test3 -- jenkins@git . .

git -c core.askpass=true ls-remote -h ssh://git@bitbucket.org/user/proj.git [ec2-user@ip-172-31-31-13 ~]$ git -c core.askpass=true ls-remote -h ssh://git@bitbucket.org/user/proj.git db710fbf01f08789cf5c15e66269013f8e1543d4 refs/heads/master

图片:

1-linux jenkins ver

2-ssh 2 git using default user

3-ssh 2 git using jenkins user

4-ssh rsa keys

5-jenkins auth keys

6-jenkins cred

7-jenkins web error

【问题讨论】:

    标签: git jenkins bitbucket permission-denied public-key


    【解决方案1】:

    当在 Jenkins 中配置它时,我会尝试将 git 存储库的 URL 写为 git@[...] 而不是 ssh://git@[...]

    另一方面,您作为test3 (ssh-rsa AAA[...]) 的私钥引入的密钥似乎不是私钥。它看起来像公钥。私钥是一个以-----BEGIN RSA PRIVATE KEY----- 开头并以-----END RSA PRIVATE KEY----- 结尾的块。在您的情况下,我认为它存储在名为 jenkins_bitbucket_access 的文件中(公钥存储在 jenkins_bitbucket_access.pub 中)

    【讨论】:

    • 没有 ssh 根本无法工作,无法连接到存储库:命令“git ls-remote -h git@bitbucket.org/user/proj.git HEAD”返回状态码 128:标准输出:标准错误:致命:'git@bitbucket.org/user/proj.git' 似乎不是 git 存储库致命:无法从远程存储库读取。请确保您具有正确的访问权限并且存储库存在
    • 我按照你的建议更新了jenkins的authorized_keys文件,还重启了jenkins服务,还是不行....还是同样的错误
    • 我没有建议更改 authorized_keys 文件,而是更改 Jenkins 上的 test3 凭据配置。顺便说一句,当您从命令行执行ssh 而不指定特定的私钥时,默认情况下您使用的是id_rsa。既然这样可行,我会在不指定任何凭据的情况下尝试 Jenkins,因此也应该使用默认密钥对,不是吗?
    • 没有ssh:// 的URL 格式略有不同 - 它需要是git@bitbucket.org:owner/repo.git,用冒号代替第一个斜杠。
    【解决方案2】:

    问题解决了! 当我在 Jenkins Web 上创建 SSH 凭据时,我使用了我的公钥而不是私钥...现在一切正常 :)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-08
      • 1970-01-01
      • 2014-06-06
      • 2019-02-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多