Search code examples
gitjenkinssshssh-keys

Access issues when trying to add Git repository to Jenkins


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 -- [email protected]: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


Solution

  • 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 [email protected]. 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.