使用 bitbucket 配置 jenkins 时出错

使用 bitbucket 配置 jenkins 时出错

当我以 jenkins 用户身份登录时,我在 ~/.ssh/id_rsa.pub 中获得了 ssh 密钥。

我已将其正确导入 bitbucket 并且它已接受密钥。

当我尝试执行 git clone(到正确的 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 clone,这会将 bitbucket url 再次添加到已知主机。

相关内容