【问题标题】:Failed to connect to repository : Command "git ls-remote -h无法连接到存储库:命令“git ls-remote -h
【发布时间】:2017-07-06 14:30:15
【问题描述】:

我在我的centos7 server 上安装了jenkins 并尝试构建maven 版本。创建了一个新的 maven 构建作业,在 SCM 中,我试图从 github 中提取代码,但它向我显示了一个错误,例如...

Failed to connect to repository : Command "git ls-remote -h https://github.com/example.git HEAD" returned status code 128: stdout:  stderr: remote: Invalid username or password. fatal: Authentication failed for 'https://github.com/example.git/'

我还为我的github 设置了一个SSH 公钥。我不知道如何解决这个问题。任何人都可以帮助我。在此先感谢。

【问题讨论】:

标签: jenkins centos7 github-for-windows


【解决方案1】:

我还为我的 github 设置了一个 SSH 公钥

这对 HTTPS URL 的影响为零:忽略 SSH 密钥。

检查你是否有一个 git 凭据助手,它可能会缓存你的凭据(GitHub 用户名/密码)

git config credential.helper

例如,it could be 'cache'

我建议(如in this answer)将其设置为gnome-keyring

git config --global credential.helper gnome-keyring

然后从命令行再次尝试您的git ls-remote

git ls-remote https://<yourUsername>@github.com/<yourUsername>/<yourRepo.git>

这应该会提示您输入 GitHub 用户名/密码。输入后,第二个git ls-remote 不应再次询问您的凭据。

从那里,来自您的 Jenkins 的 SCM 流程,只要所说的 Jenkins 使用您的帐户运行,就应该可以工作。

【讨论】: