Jenkins git 身份验证在 Windows 上使用正确的凭据失败

Jenkins git authentication failed with correct credentials on Windows

我目前在 Windows 10 上使用 Jenkins,并使用 git 作为版本控制系统。 尽管我提供了正确的存储库 URL 和凭据,但我无法使用 jenkins 并出现以下错误。

Failed to connect to repository : Command "git.exe ls-remote -h REPOSITORY_URL HEAD" returned status code 128:
stdout:
stderr: git@URL: Permission denied (publickey).
fatal: Could not read from remote repository.

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

Credential 和 URL 似乎没有错,因为此构建之前使用相同的凭据成功。成功构建后唯一的变化是构建脚本中的一行。

git config --global core.sshCommand C:/Windows/System32/OpenSSH/ssh.exe

我用这个脚本成功后,git设置一直失败。那条线有问题吗?我该如何解决?

编辑
问题解决了!对于任何有同样问题的人,这是系统用户的问题!由于 ssh 密钥存储在每个用户 space 中,jenkins 无法检测到 ssh 密钥所在的位置。因此,进入windows中的'service',将jenkins服务的用户修改为正确ssh key的用户。它解决了我的问题!

Seems there is some problem in Jenkins.
It cannot locate OpenSSH folder in System32, and so that I cannot get log with it.

这可以解释为什么主 Jenkins 控制器(在旧术语中也称为“master”)无法联系 Git 存储库(假设这里是 SSH URL,技术远程用户帐户“git")

尝试删除 git 配置以查看错误是否仍然存在:Git 应该回退到它自己的 ssh.exe,与 Git 一起打包 For Windows.

正如 OP 所指出的,这仅在 Jenkins 是 运行 作为用户帐户而不是 system account.
时才有效 只有这样它才能访问 %USERPROFILE%\.ssh 文件夹。