Jenkins:Git 克隆失败,找不到匹配的密钥交换方法

发布于 2025-01-16 13:42:23 字数 4336 浏览 2 评论 0原文

我正在使用 Jenkins 版本 - 2.332.1 ,并且 jenkins gerrit 存储库 ssh 克隆有问题。详细信息如下,

Jenkins Git plugin Version 4.10.3 

构建服务器环境:-

$ ssh -V
OpenSSH_8.2p1 Ubuntu-4ubuntu0.3, OpenSSL 1.1.1f  31 Mar 2020

$ git --version
git version 2.33.1

Jenkins 构建控制台日志:-

11:35:13  > git config remote.origin.url ssh://[email protected]:29418/ndk/linux/kernal-image # timeout=10
11:35:13 Fetching upstream changes from ssh://[email protected]:29418/ndk/linux/kernal-image
11:35:13  > git --version # timeout=10
11:35:13  > git --version # 'git version 2.33.1'
11:35:13  > git fetch --tags --force --progress -- ssh://[email protected]:29418/ndk/linux/kernal-image +refs/heads/*:refs/remotes/origin/* # timeout=10
11:35:13 ERROR: Error fetching remote repo 'origin'
11:35:13 hudson.plugins.git.GitException: Failed to fetch from ssh://[email protected]:29418/ndk/linux/kernal-image
11:35:13    at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:1001)
11:35:13    at hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:1242)
11:35:13    at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1302)
11:35:13    at hudson.scm.SCM.checkout(SCM.java:540)
11:35:13    at hudson.model.AbstractProject.checkout(AbstractProject.java:1215)
11:35:13    at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:645)
11:35:13    at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:85)
11:35:13    at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:517)
11:35:13    at hudson.model.Run.execute(Run.java:1896)
11:35:13    at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:44)
11:35:13    at hudson.model.ResourceController.execute(ResourceController.java:101)
11:35:13    at hudson.model.Executor.run(Executor.java:442)
11:35:13 Caused by: hudson.plugins.git.GitException: Command "git fetch --tags --force --progress -- ssh://[email protected]:29418/ndk/linux/kernal-image +refs/heads/*:refs/remotes/origin/*" returned status code 128:
11:35:13 stdout: 
11:35:13 stderr: Unable to negotiate with 165.55.66.77 port 29418: no matching key exchange method found. Their offer: diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
11:35:13 fatal: Could not read from remote repository.
11:35:13 
11:35:13 Please make sure you have the correct access rights
11:35:13 and the repository exists.
11:35:13 
11:35:13    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2671)
11:35:13    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:2096)
11:35:13    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.access$500(CliGitAPIImpl.java:84)
11:35:13    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$1.execute(CliGitAPIImpl.java:618)
11:35:13    at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:999)
11:35:13    ... 11 more
11:35:13 ERROR: Error fetching remote repo 'origin'
11:35:13 Finished: FAILURE

在终端上 ssh 连接到 gerrit 有效,结果如下,

$ ssh -p 29418 [email protected]

  ****    Welcome to Gerrit Code Review    ****

  Hi ProUser ., you have successfully connected over SSH.

  Unfortunately, interactive shells are disabled.
  To clone a hosted Git repository, use:

  git clone ssh://[email protected]:29418/REPOSITORY_NAME.git

用 jenkins 解决问题。请帮助我找到可能的解决方法。

I'm using Jenkins version - 2.332.1 and i have problem with jenkins gerrit repository ssh clone. The details as follows,

Jenkins Git plugin Version 4.10.3 

Build server environment:-

$ ssh -V
OpenSSH_8.2p1 Ubuntu-4ubuntu0.3, OpenSSL 1.1.1f  31 Mar 2020

$ git --version
git version 2.33.1

Jenkins Build console Log:-

11:35:13  > git config remote.origin.url ssh://[email protected]:29418/ndk/linux/kernal-image # timeout=10
11:35:13 Fetching upstream changes from ssh://[email protected]:29418/ndk/linux/kernal-image
11:35:13  > git --version # timeout=10
11:35:13  > git --version # 'git version 2.33.1'
11:35:13  > git fetch --tags --force --progress -- ssh://[email protected]:29418/ndk/linux/kernal-image +refs/heads/*:refs/remotes/origin/* # timeout=10
11:35:13 ERROR: Error fetching remote repo 'origin'
11:35:13 hudson.plugins.git.GitException: Failed to fetch from ssh://[email protected]:29418/ndk/linux/kernal-image
11:35:13    at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:1001)
11:35:13    at hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:1242)
11:35:13    at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1302)
11:35:13    at hudson.scm.SCM.checkout(SCM.java:540)
11:35:13    at hudson.model.AbstractProject.checkout(AbstractProject.java:1215)
11:35:13    at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:645)
11:35:13    at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:85)
11:35:13    at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:517)
11:35:13    at hudson.model.Run.execute(Run.java:1896)
11:35:13    at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:44)
11:35:13    at hudson.model.ResourceController.execute(ResourceController.java:101)
11:35:13    at hudson.model.Executor.run(Executor.java:442)
11:35:13 Caused by: hudson.plugins.git.GitException: Command "git fetch --tags --force --progress -- ssh://[email protected]:29418/ndk/linux/kernal-image +refs/heads/*:refs/remotes/origin/*" returned status code 128:
11:35:13 stdout: 
11:35:13 stderr: Unable to negotiate with 165.55.66.77 port 29418: no matching key exchange method found. Their offer: diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
11:35:13 fatal: Could not read from remote repository.
11:35:13 
11:35:13 Please make sure you have the correct access rights
11:35:13 and the repository exists.
11:35:13 
11:35:13    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2671)
11:35:13    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:2096)
11:35:13    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.access$500(CliGitAPIImpl.java:84)
11:35:13    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$1.execute(CliGitAPIImpl.java:618)
11:35:13    at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:999)
11:35:13    ... 11 more
11:35:13 ERROR: Error fetching remote repo 'origin'
11:35:13 Finished: FAILURE

On terminal ssh connection to gerrit works, the result as follows,

$ ssh -p 29418 [email protected]

  ****    Welcome to Gerrit Code Review    ****

  Hi ProUser ., you have successfully connected over SSH.

  Unfortunately, interactive shells are disabled.
  To clone a hosted Git repository, use:

  git clone ssh://[email protected]:29418/REPOSITORY_NAME.git

To solve the problem with jenkins. Kindly help me with the possible workarounds.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小糖芽 2025-01-23 13:42:24

在运行 Jenkins 控制器的服务器上(假设它与您手动测试 ssh 连接的服务器相同),添加到 .bashrc

export GIT_SSH_COMMAND='ssh -Tv'

这将允许准确查看运行的 SSH 命令以及它在哪里寻找 SSH 密钥一对。

为此,您需要仔细检查 Jenkins 控制器正在运行的帐户(root,或您自己用于手动测试的相同用户帐户)

,而且问题还在于默认使用的端口不是 29418,但是 22。

为了确保您使用正确的端口(再次假设 Jenkins 使用与您正在使用的用户帐户相同的用户帐户运行):

  • 将 Gerrit 服务器 URL 替换为

    gerrit:REPOSITORY_NAME.git
    
  • 添加 ~/.ssh/config 文件:

Host gerrit
  Hostname 165.55.66.77
  User prj-user
  Port 29418
  IdentityFile ~/.ssh/TheRightPrivateKey
  KexAlgorithms +diffie-hellman-group1-sha1,diffie-hellman-group1-sha1

这样,您就可以确定 SSH URL/命令是正确的,使用正确的端口/密钥/用户/主机名。

On the server where the Jenkins controller is running (assuming it is the same as the one where you tested your ssh connection manually), add to the .bashrc

export GIT_SSH_COMMAND='ssh -Tv'

That will allow to see exactly what SSH command is run and where it seeks its SSH key pair.

For that, you need to double-check with which account the Jenkins controller is running (root, or the same user account you used yourself for your manual test)

And the issue is also the port used by default is not 29418, but 22.

To make sure you are using the right port (again, assuming Jenkins runs with the same user account as the one you are using):

  • replace the Gerrit server URL with

    gerrit:REPOSITORY_NAME.git
    
  • add a ~/.ssh/config file with:

Host gerrit
  Hostname 165.55.66.77
  User prj-user
  Port 29418
  IdentityFile ~/.ssh/TheRightPrivateKey
  KexAlgorithms +diffie-hellman-group1-sha1,diffie-hellman-group1-sha1

That way, you are sure the SSH URL/command will be the right one, using the right port/key/user/hostname.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文