配置 jenkins 時出現 bitbucket 錯誤

配置 jenkins 時出現 bitbucket 錯誤

當我以 jenkins 使用者身分登入時,我在 ~/.ssh/id_rsa.pub 中有一個 ssh 金鑰。

我已將其正確導入到 bitbucket 中,並且它已接受密鑰。

當我嘗試進行 git 克隆(到正確的 URL)時,我仍然得到...

Building in workspace /var/lib/jenkins/jobs/Google adwords/workspace
Checkout:workspace / /var/lib/jenkins/jobs/Google adwords/workspace - hudson.remoting.LocalChannel@2c473996
Using strategy: Default
Cloning the remote Git repository
Cloning repository origin
ERROR: Error cloning remote repo 'origin' : Could not clone [email protected]:DAVID99WORLD/assessme.git
hudson.plugins.git.GitException: Could not clone [email protected]:DAVID99WORLD/assessme.git
    at hudson.plugins.git.GitAPI.clone(GitAPI.java:268)
    at hudson.plugins.git.GitSCM$2.invoke(GitSCM.java:1122)
    at hudson.plugins.git.GitSCM$2.invoke(GitSCM.java:1064)
    at hudson.FilePath.act(FilePath.java:842)
    at hudson.FilePath.act(FilePath.java:824)
    at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1064)
    at hudson.model.AbstractProject.checkout(AbstractProject.java:1256)
    at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:589)
    at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:88)
    at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:494)
    at hudson.model.Run.execute(Run.java:1502)
    at hudson.maven.MavenModuleSetBuild.run(MavenModuleSetBuild.java:477)
    at hudson.model.ResourceController.execute(ResourceController.java:88)
    at hudson.model.Executor.run(Executor.java:236)
Caused by: hudson.plugins.git.GitException: Command "git clone --progress -o origin [email protected]:DAVID99WORLD/assessme.git /var/lib/jenkins/jobs/Google adwords/workspace" returned status code 128:
stdout: Cloning into '/var/lib/jenkins/jobs/Google adwords/workspace'...

stderr: Host key verification failed.
fatal: The remote end hung up unexpectedly

有人知道會發生這種情況的原因嗎?根據我所讀過的文檔, ~/.ssh 是該文件存在的 jenkins 使用者的正確目錄。

編輯:我的 jenkins 用戶在 ~/.ssh 中沒有known_hosts 文件,但我的根級別文件有 - 應該嗎?我可以用我的 jenkins 用戶進行克隆,而且它根本沒有將主機作為 jenkins 用戶提及。

答案1

您應該有私鑰,而不僅僅是公鑰。如果您的公鑰是id_rsa.pub,那麼您的私鑰可能已命名id_rsa

我假設您從其他系統(也許是您的本機桌面)複製了此公鑰?

您也可以將對應的私鑰複製到 jenkins~/.ssh目錄,也可以為 jenkins 使用者產生一個新的金鑰對並將該公鑰匯入到 bitbucket 中。

要產生新的 ssh 金鑰對:

cd ~/.ssh
ssh-keygen -t rsa

這將產生以下輸出:

Generating public/private rsa key pair.
Enter file in which to save the key (/home/b/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/jenkins/.ssh/id_rsa.
Your public key has been saved in /home/jenkins/.ssh/id_rsa.pub.

答案2

實際問題似乎是 bitbucket 伺服器不在我的已知主機清單中。必須以 jenkins 使用者身分登入並再次執行 git 克隆,這會再次將 bitbucket url 新增至已知主機。

相關內容