Jenkins 无法连接到存储库:命令返回状态代码 128:

Jenkins Failed to connect to repository : Command returned status code 128:

好的,所以我花了数年时间尝试设置这个 jenkins 服务器,但到处都是错误。 大多数答案都是针对 linux,这个 jenkins 服务器在 windows 上(如果你知道如何在 linux jenkins 上设置 msbuild,我会洗耳恭听)。

服务器设置完全正确,我正在做的最后一件超级超级基本的事情是尝试从 aws codecommit 中提取 repo,我有正确的角色和凭证。

我收到这条消息

Jenkins Failed to connect to repository :
"git.exe ls-remote -h https://repo-url HEAD" Command  returned status code 128:

接着说

stderr: fatal: unable to access 'https://repo-url': The requested URL returned error: 403

然而,将相同的命令复制到 cmd window 中,它工作得很好。

有一个名为 codecommit-url-helper 的插件,我也安装并试用了它,但它所做的只是让我的希望和梦想落空。

如果您的解决方案涉及 jenkins cli,请知道我也尝试过,但是:

C:\Users\Administrator\Downloads> java -jar jenkins-cli.jar -s http://localhost:8080/ help
Sep 21, 2016 2:14:33 PM hudson.remoting.SynchronousCommandTransport$ReaderThread run
SEVERE: I/O error in channel Chunked connection to http://localhost:8080/cli

[更新]

对于那些想知道我最终做了两件事的人,使用 git config --system 配置具有角色的凭据,然后我在 "Git plugin" 之一的 jenkins 系统设置中添加了全局用户名和电子邮件他们做到了。

使用 SSH 密钥很好。 SSH 密钥是一种无需密码即可识别受信任计算机的方法。您可以生成 SSH 密钥并将 public 密钥添加到您的 GitHub 帐户。请检查 How to Generate SSH in Github 了解更多详情

RejeeshChandran的回答很好的解决了这个问题。我为完成它而执行的实际步骤:

1) 使用提供的说明生成新的 SSH 密钥并将其添加到 ssh-agent here

2) 重启 Jenkins 服务

3) git.exe ls-remote -h https://repo-url HEAD 命令现在在 Jenkins 中可以正常工作

另一种选择是利用 IAM 用户及其 Codecommit https 凭证。

因此,您可以将这些凭据添加到 Jenkins。在 Jenkins 作业中,您可以将它们设置为在从该 repo 检出时使用。

不过请记住,应该控制 IAM 权限。您可以简单地允许该 IAM 用户拥有对 Codecommit 的完全访问权限。

您也可以在编写 Jenkins 管道时使用这些凭据。

希望对您有所帮助。