git - 尝试将 Git 存储库添加到 Jenkins 时出现访问问题

标签 git jenkins ssh ssh-keys

我正在 Jenkins 中创建一条管道。当我尝试添加存储库 URL 时,出现以下错误:

Failed to connect to repository : Command "git.exe ls-remote -h -- [email protected]:somename/myproject.git HEAD" returned status code 128: stdout: stderr: Host key verification failed. fatal: Could not read from remote repository.

Please make sure you have the correct access rights and the repository exists.

显示我添加它的位置的屏幕截图: enter image description here

我在这里更改了存储库名称作为示例,但我正在访问的存储库是有效且公开的,任何人都可以访问。

谷歌搜索不断回到 ssh 的问题。我不确定是否与我有关。在我执行此操作的计算机上,我能够处理该存储库(通过终端或 ide pull/推),因为我已经为我的 bitbucket 设置了 ssh key ,并且工作正常。

我是否应该为 Jenkins 单独设置另一组 ssh key ?我很困惑。我可以得到一些帮助吗?谢谢。

编辑:

如果我添加 github 存储库,则不会出现任何问题,例如如下所示: https://github.com/bradtraversy/vanilla-parcel-boilerplate.git

最佳答案

根据您的评论,这适用于 https,无需任何身份验证,但您仍然需要通过 ssh 连接以用于其他目的和用途。为了能够连接,您必须:

  • 注册远程主机 key ,以便将 Jenkins 用户系统帐户识别为已知主机
  • 在 Jenkins GUI 中将私钥注册为凭证,以便在远程目标上进行身份验证

接受主机 key 作为已知主机

最简单的方法是使用 ssh 连接到您的 Jenkins 服务器并成为 jenkins系统用户。从那里使用 ssh <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="accbc5d8eccec5d8ced9cfc7c9d882c3decb" rel="noreferrer noopener nofollow">[email protected]</a> 启动到目标服务器的 ssh 连接。 。您将收到以下提示

The authenticity of host 'bitbucket.org (2406:da00:ff00::22c5:2ef4)' can't be established.
RSA key fingerprint is SHA256:zzXQOXSRBEiUtuE8AikJYKwbHaxvSc0ojez9YXaGp1A.
Are you sure you want to continue connecting (yes/no)?

回答 yes 将主机 key 存储在您的known_hosts 文件中。您可以取消其余的连接操作。

注册私钥。

您需要将您的私有(private) ssh key 注册为 Jenkins 中的凭据。请参阅documentation为了那个原因。完成后,凭据将显示在存储库 URL 下的下 pull 列表中。选择它以将其用于连接。

关于git - 尝试将 Git 存储库添加到 Jenkins 时出现访问问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61290041/

相关文章:

python - 使用基于主机的身份验证无需密码的 Paramiko ssh

Git Fetch 与 Git Fetch Origin

git - 我可以让 git 创建两个文件来 merge (我的和他们的)而不是一个吗

node.js - 尝试安装 git 存储库时出现 npm 错误

ssh - 如何在 Ansible 的一个 list 中使用多个私钥

perl - 获取通过 $self->send() 在 Perl Expect 模块中的远程主机上执行的命令的输出

Git 提交显示在日志中但不在 Github 中

jenkins - 使用 Jenkins、Gradle Artifactory 插件配置发布阶段

Jenkins ,复制目录的内容

Jenkins 声明性管道抛出 org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException : unclassified getAt method