簡體   English   中英

Jenkins 管道 Git 錯誤:連接到遠程存儲庫時“主機密鑰驗證失敗”

[英]Jenkins pipeline Git error: “Host Key Verification Failed” when connecting to remote repository

我正在使用我的 PC 作為服務器來使用聲明性管道構建我的 Jenkins 腳本。

在 git bash 上運行 git clone 時,它​​運行良好:

$ 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 文件從我的 guillaumed 用戶 ssh 路徑復制到 SYSTEM ssh 路徑,但如果我使用 SYSTEM 用戶而不是 guillaumed 用戶登錄,則無法使用它。

我需要做什么?

這個鏈接沒有幫助。

實際上,如果您以 SYSTEM 身份登錄,則無法使用 ssh 結帳。

要以“thisUser”的身份結帳:

你需要配置你的詹金斯。

1/ 添加一個用戶“thisUser”

2/ 添加用戶的 ssh 憑證“thisUser-ssh-credentials”

3/ 使用 ssh-agent 插件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"
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM