0

I've got an ssh key in ~/.ssh/id_rsa.pub when I login as the jenkins user.

I've imported this into bitbucket correctly and it has accepted the key.

When I try to do a git clone (to the correct URL) I still get....

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 git@bitbucket.org:DAVID99WORLD/assessme.git
hudson.plugins.git.GitException: Could not clone git@bitbucket.org: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 git@bitbucket.org: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

Does anyone know of a reason why this would occur? According to the documentation I've read ~/.ssh is the correct directory as the jenkins user for this file to exist.

EDIT : My jenkins user does not have a known_hosts file in ~/.ssh but my root level ones do - should it? I can do a clone with my jenkins user just fine and it doesn't mention the host at all as jenkins user.

David
  • 143
  • 1
  • 1
  • 6

2 Answers2

1

You should have the private key there, not just the public key. If your public key is id_rsa.pub, your private key is probably named id_rsa.

I assume you copied this public key from some other system (perhaps your local desktop)?

You can either copy the corresponding private key to the jenkins ~/.ssh directory as well, or you can generate a new keypair for your jenkins user and import that public key in bitbucket.

To generate a new ssh keypair:

cd ~/.ssh
ssh-keygen -t rsa

This will generate the following output:

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.
brain99
  • 1,772
  • 11
  • 18
0

The actual problem appeared to be the bitbucket server wasn't in my list of known-hosts. Had to login as the jenkins user and do a git clone again, this added the bitbucket url again to known hosts.

David
  • 143
  • 1
  • 1
  • 6
  • Yes, this is the problem. But there should be a way to avoid the manual login - seems this is missing. Either a GUI option to disable the check or add the key in Jenkins. – Axel Heider Aug 12 '22 at 14:39