【问题标题】:Jenkins: Git Failed to connect to repository, returned status code 128Jenkins:Git 无法连接到存储库,返回状态码 128
【发布时间】:2026-01-18 22:30:01
【问题描述】:

我正在尝试克隆远程 GitHub 企业存储库,并在将远程存储库的 URL 添加到我的 Jenkins 配置中的 Git 插件后遇到以下错误:

Failed to connect to repository : Command "git.exe ls-remote -h https://<<server>>/M/AS.git HEAD" returned status code 128:
stdout: 
stderr: fatal: unable to access 'https://<<server>>/M/AS.git/': Received HTTP code 502 from proxy after CONNECT

【问题讨论】:

标签: jenkins github


【解决方案1】:

首先,您还需要在下面的部分中使用 jenkins 设置 github

转到Github --> click on profile dropdown --> settings --> devloper settings --> personal access token --> generate new token --> select all scopes --> copy the token

那就去Jenkins --> manage Jenkins --> github settings --> add user --> Select secret text--> paste the token

然后通过单击测试按钮测试 git-hub 连接如果成功,Jenkins 将准备克隆 GitHub 存储库

还在 GitHub 中添加 Webhook、集成和服务

【讨论】:

    【解决方案2】:

    确保您已经在 Git 存储库中生成了 Git API 令牌,并在 Jenkins 凭证中添加了相同的令牌。 如果完成,我认为将 Git 连接到 Jenkins 不会有任何问题。

    您还可以测试您的 Git 服务器是否能够 ping 您的 Jenkins 服务器。 (如果您正在运行自己的 Git 和 Jenkins)。

    一切顺利。

    【讨论】:

      【解决方案3】:

      检查失败的作业环境变量。

      如果没有名为 NO_PROXY 的环境变量,请在 JENKINS 作业的配置中设置一个:

      NO_PROXY=.mycompany.com
      

      在这里,我假设您的 GitHub Enterprise 有一个类似 myserver.mycompany.com 的 URL(替换(mycompany.com 自己)

      这将避免 Jenkins 尝试通过代理访问远程服务器。

      【讨论】:

        【解决方案4】:

        如果您从 VM 运行,请确保安装包“git-core”。

        你必须在运行 jenkins 的机器上安装了 git

        【讨论】:

          【解决方案5】:

          我遇到了同样的问题,对我来说,它有助于重新启动安装 Jenkins 的机器。

          【讨论】: