【问题标题】:Git SSH checkout fails with Jenkins and GitLabJenkins 和 GitLab 的 Git SSH 签出失败
【发布时间】:2021-12-06 12:28:22
【问题描述】:

当我尝试构建配置为从 GitLab 签出的 Jenkins 作业时,我得到以下错误输出(截断):

    ....................
ERROR: Error fetching remote repo 'origin'
hudson.plugins.git.GitException: Failed to fetch from git@10.777.77.777:root/xxx.git
    at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:1001)
    at hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:1242)
    at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1302)
    ....................................................
        ....................................................
    at hudson.model.Executor.run(Executor.java:431)
Caused by: hudson.plugins.git.GitException: Command "git fetch --tags --force --progress -- git@10.777.77.777:root/xxx.git +refs/heads/*:refs/remotes/origin/*" returned status code 128:
stdout: 
stderr: Load key "/var/lib/jenkins/workspace/gitlabjenkinsdemo@tmp/jenkins-gitclient-ssh1964800292912998995.key": invalid format
Permission denied, please try again.
Permission denied, please try again.
git@10.170.8.204: Permission denied (publickey,password).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2681)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:2102)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.access$500(CliGitAPIImpl.java:86)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$1.execute(CliGitAPIImpl.java:624)
at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:999)
... 11 more

错误:获取远程 repo 'origin' 时出错 完成:失败

我正在尝试按照这篇帖子 Jenkins_Gitlab 设置 CI/CD 管道

我希望我添加的私钥应该能够开箱即用地签出(注意:Jenkins 服务器和 Gitlab 服务器都在同一个 Debian 实例上运行)。

在 ~/.ssh 目录中,我有以下内容:

root@myservername:~/.ssh# ls -ld
drwx------ 2 root root 4096 Oct 18 15:30 .

在我的 Jenkins 工作的源代码管理选项卡中,我还在 Gitlab 中添加了 我从项目中提取的 SSH 链接。但是,我不确定的是该项目在 Gitlab 中显示的以下消息:

我错过了什么?

【问题讨论】:

    标签: jenkins ssh gitlab


    【解决方案1】:

    Jenkins 服务器和 Gitlab 服务器都运行在同一个 Debian 实例上

    理想情况下,他们将使用自己的关联服务帐户运行,而不是“root”。

    但是,即使是 root,这也应该有效。
    检查您添加了哪个私有 SSH 密钥,并确保至少在测试时它没有受到密码保护(即private key file does not have a Proc-Type: 4,ENCRYPTED line in it

    这可能是您拥有jenkins-gitclient-ssh1964800292912998995.key": invalid format 的原因。
    (或者您已经使用 CRLF 而不是 LF 作为行尾复制了私钥文件内容)
    (或者您复制了一个公钥,而应该是私钥,反之亦然)

    来自discussion

    • 必须在 Jenkins 中再次注册私钥(确保其 eol -- end-of-line -- 是 LF,而不是 CRLF)
    • 分支需要重命名:

    当我做git init 时,我的仓库有master,所以当我设置GitLab 远程时必须将分支重命名为main

    【讨论】:

    • 我复制了正确的密钥(私钥)。 SSH 密钥被创建为无密码(我已经检查了 Proc-Type:4,Encrypted 也作为快速验证).. 另一方面,我如何检查我是否使用 CRLF 复制了文件内容,或者修改了我的复制方式.
    • @Golide 好的。您能否尝试从您的 Jenkins 服务器以 root 身份(我想,意思是 ~/.ssh 具有公钥和私钥的帐户)执行 ssh -i /path/to/private/key -Tv git@10.777 .77.777,看看 GitLab 是否正确验证了你。
    • 身份验证成功(公钥)。已通过 10.777.77.777 ([10.777.77.777]:22) 的身份验证。 debug1:通道 0:新的 [client-session] debug1:请求 no-more-sessions@openssh.com debug1:进入交互式会话。 debug1:承诺:网络 debug1:client_input_global_request:rtype hostkeys-00@openssh.com want_reply 0 debug1:远程:/var/opt/gitlab/.ssh/authorized_keys:1:密钥选项:命令 user-rc debug1:远程:/var /opt/gitlab/.ssh/authorized_keys:1: key options: command user-rc debug1: 发送环境。 debug1: 发送 env LANG = en_ZW.UTF-8 欢迎来到 GitLab,@root!
    • 这是有效的
    • @Golide 詹金斯可能没有以 root 身份运行吗? (尽管它应该仍然可以工作,因为 Jenkins 不是在寻找您的 ~root/.ssh/ 私钥,而是应该将其存储在自己的私有凭据中)
    猜你喜欢
    • 2015-07-17
    • 2018-10-19
    • 2022-11-13
    • 2019-08-16
    • 2021-11-07
    • 2016-06-07
    • 2013-02-20
    • 1970-01-01
    • 2014-04-08
    相关资源
    最近更新 更多