2

I am creating a pipeline in Jenkins. When I try to add the repository URL, I am getting following error:

Failed to connect to repository : Command "git.exe ls-remote -h -- git@bitbucket.org:somename/myproject.git HEAD" returned status code 128: stdout: stderr: Host key verification failed. fatal: Could not read from remote repository.

Please make sure you have the correct access rights and the repository exists.

Screen shot to show where I am adding it: enter image description here

I changed the repo name as an example here but the repo I am accessing is valid and public, anyone can access.

Googling around keeps going back to issue with ssh. I am not sure if it is related to me. On the machine where I am doing this, I am able to work on that repo (pull/push via terminal or ide) cos I already have my ssh keys set up for my bitbucket and it works fine.

Am I supposed to setup another set of ssh keys separately for Jenkins? Am confused. Could I get some assistance on this please? Thanks.

EDIT:

To note no issue if I add a github repo for example as follows: https://github.com/bradtraversy/vanilla-parcel-boilerplate.git

phd
  • 82,685
  • 13
  • 120
  • 165
kar
  • 4,791
  • 12
  • 49
  • 74
  • 1
    If this is a public repo (anonymous read allowed), use an http(s) url rather than ssh. Using ssh cannot be done anonymously. If you still need/want to use ssh, you will have to 1) add the target server host key in `/home/jenkins/.ssh/known_hosts` (either manually or by initiating a first ssh connection with the jenkins user from the command line) 2) configure a private key credential in jenkins to use with that connection. – Zeitounator Apr 18 '20 at 14:00
  • @Zeitounator Thanks. It does work with https. For your point 1, by manually, do you mean adding my current ssh key values which I already have used to connect to bitbucket? Plus is .ssh something I add myself? Cos its not there even though I can see other hidden folders. – kar Apr 18 '20 at 14:11
  • Does this answer your question? [Git error: "Host Key Verification Failed" when connecting to remote repository](https://stackoverflow.com/questions/13363553/git-error-host-key-verification-failed-when-connecting-to-remote-repository) – phd Apr 18 '20 at 16:33
  • https://stackoverflow.com/search?q=%5Bgit%5D+Host+key+verification+failed – phd Apr 18 '20 at 16:33

1 Answers1

2

From your comment this works with https without any authentication but you still need to connect through ssh for other purposes and usage. To be able to connect you have to:

  • register the remote host key to be recognized as a known host for Jenkins user system account
  • register a private key as a credential in Jenkins GUI to get authenticated on the remote target

Accept the host key as known host

The easiest way to do this is to connect to your Jenkins server with ssh and to become jenkins system user. From there initiate an ssh connection to your target server with ssh git@bitbucket.org. You will get the following prompt

The authenticity of host 'bitbucket.org (2406:da00:ff00::22c5:2ef4)' can't be established.
RSA key fingerprint is SHA256:zzXQOXSRBEiUtuE8AikJYKwbHaxvSc0ojez9YXaGp1A.
Are you sure you want to continue connecting (yes/no)?

Answer yes to store the host key in you known_hosts file. You can cancel the rest of the connection operation.

Register a private key.

You will need to register your private ssh key as a credential in Jenkins. See the documentation for that. Once you're done, the credential will show up in the drop down under the repository url. Select it to use it for the connection.

Zeitounator
  • 38,476
  • 7
  • 53
  • 66