Jenkins 管道 Git 错误:"主机密钥验证失败"连接到远程仓库时



我正在使用我的PC作为服务器来构建带有声明式管道的Jenkins脚本。

在 git bash 上运行 git 克隆时,它运行良好:

$ git clone ssh://guillaumed@myserver.com:29418/myProjects/thisProject.git ThisFirmware
Cloning into 'ThisFirmware'...
remote: Counting objects: 889, done
remote: Finding sources: 100% (203/203)
Receiving objects:  79% (121769/152721), 48.11 MiB | 10.35 MiB/s

但是通过流水线在同一台机器上运行它:

sh "git clone ssh://guillaumed@myserver.com:29418/myProjects/thisProject.git ThisFirmware"

给我以下错误

[Pipeline] sh
+ git clone ssh://guillaumed@myserver.com:29418/myProjects/thisProject.git ThisFirmware
Cloning into 'ThisFirmware'...
Host key verification failed.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.

有什么提示吗?

为了确保我使用相同的密钥,感谢 Jens,管道脚本找不到密钥。

  • 在管道上做cat ~/.ssh/id_rsa.pub,结果是+ cat /c/windows/system32/config/systemprofile/.ssh/id_rsa.pub cat: /c/windows/system32/config/systemprofile/.ssh/id_rsa.pub: No such file or directory

  • 所以我将 ssh 文件从我的纪尧用户 ssh 路径复制到系统 ssh 路径,但如果我使用 SYSTEM 用户而不是纪尧用户登录,我就无法使用它。

我该怎么做?

此链接没有帮助。

事实上,如果您以系统身份登录,则无法使用 ssh 结帐。

要以"此用户"身份结账:

你需要配置你的 Jenkins。

1/添加用户"此用户">

2/添加用户的 ssh 凭据"thisUser-ssh-credentials">

3/使用 SSH 代理插件 https://wiki.jenkins.io/display/JENKINS/SSH+Agent+Plugin

然后配置管道

dir(server_workspace) 
{
sshagent(credentials: ['thisUser-ssh-credentials'] ) 
{
sh "git clone ssh://thisUser@domain.com:port/yourProjects/thisProject.git"
}
}

最新更新