Git Jenkins 和 GitLab 的 SSH 校验失败

Git SSH checkout fails with Jenkins and GitLab

当我尝试构建配置为从 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.access0(CliGitAPIImpl.java:86)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.execute(CliGitAPIImpl.java:624)
at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:999)
... 11 more

错误:获取远程仓库时出错 'origin' 已完成:失败

我正在尝试根据此设置 CI/CD 管道 post Jenkins_Gitlab

我预计我添加的私钥应该启用开箱即用的结帐(注意:Jenkins 服务器和 Gitlab 服务器都在同一个 Debian 实例上 运行)。

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

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

在我的 Jenkins 作业的源代码管理选项卡中,我还添加了我从项目[=34 中提取的 SSH link =] 在 Gitlab 中。但是我不确定的是项目在 Gitlab 中显示的消息:

我错过了什么?

Both Jenkins server and Gitlab server are running on the same Debian instance

理想情况下,他们会 运行 使用自己的关联服务帐户,而不是“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 作为行尾复制了私钥文件内容)
(或者您已经复制了一个 public 密钥,其中需要一个私有密钥,反之亦然)

来自discussion:

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

My repo had master when I did git init, so had to rename branch to main when I set the GitLab remote