【问题标题】:ssh: Could not resolve hostname gitlab.com:user_name/repo_name.git: Name or service not knownssh:无法解析主机名 gitlab.com:user_name/repo_name.git:名称或服务未知
【发布时间】:2022-01-17 18:18:48
【问题描述】:

我正在尝试将我的 jenkins 服务器连接到我在 gitlab.com 上的私有存储库。 我已经将 gitlab 的 API 访问令牌添加到我的 jenkins 服务器,并将 Jenkins 公钥添加到 gitlab 帐户的 ssh-keys。

将我的 gitlab 存储库添加到我的 jenkins 管道后,出现以下错误:

Failed to connect to repository : Command "git ls-remote -h -- git@gitlab.com:user_name/repo_name.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. 

当我尝试在我的 Jenkins 服务器上运行以下命令时:

ssh -T  git@gitlab.com:user_name/repo_name.git 

我收到以下错误:

ssh: Could not resolve hostname gitlab.com:user_name/repo_name.git: Name or service not known

即使在提供 SSH 密钥和访问令牌之后,我也无法弄清楚我的 Jenkins 服务器无法访问存储库的原因。

【问题讨论】:

    标签: jenkins gitlab jenkins-pipeline gitlab-api


    【解决方案1】:

    gitlab的API访问令牌

    这将用于 HTTPS 访问。

    将 Jenkins 公钥添加到 gitlab 帐户的 ssh-keys 中

    这与 SSH URL 相关,意味着您需要在 Jenkins 作业中设置正确的凭据(引用 Jenkins 私钥的凭据,其公钥已发布到 GitLab)

    我会先在 Jenkins 服务器上测试:

    ssh -Tv git@gitlab.com
    

    还要检查您的 Jenkins 服务器运行帐户 ~/.ssh/config 文件中的任何 gitlab.com Host 条目的内容。

    【讨论】:

    • 在我的 jenkins 服务器上运行 ssh -T git@gitlab.com 时,它会给出 Welcome to GitLab, @user_name. 而如果我给出完整的 repo url,我会收到 Welcome to GitLab 错误。
    • @AyushKapil 你的意思是“Could not resolve hostname”错误吗?您的 Jenkins 帐户(运行 Jenkins 服务器)是否有 ~/.ssh/config 文件? “我的 jenkins 服务器的 gitlab 的 API 访问令牌”:它是否作为凭证添加到您的 Jenkins 中(使用凭证 Jenkins 插件)?
    • 完全错误看起来像:ssh: Could not resolve hostname gitlab.com:user_name/repo_name.git: Name or service not known 另外因为我已经在 jenkins 作业上添加了正确的私钥,我已经将其公钥添加到了 gitlab 帐户。
    • @AyushKapil 你能张贴你设置 URL 和凭据的工作页面的屏幕截图吗?
    猜你喜欢
    • 2013-08-10
    • 2019-12-18
    • 2013-12-13
    • 1970-01-01
    • 2014-09-18
    • 2021-08-18
    • 1970-01-01
    • 1970-01-01
    • 2019-04-07
    相关资源
    最近更新 更多