ashwaqar ashwaqar - 6 months ago 39
Git Question

Jenkins - SSH Repository URL unable to connect

I have installed Jenkins in CentOS and also installed git plugin so as to use Bitbucket. When adding Repository URL in Source Code Management, HTTPS works good but when I add SSH url the following error pops up -

Failed to connect to repository : Command "git -c core.askpass=true ls-remote -h HEAD" returned status code 128:
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.

I have googled for this but didn't find any answers to my problem, I would like to use ssh rather than Https so please help.


I have finally found solution for my problem, I am posting it here for others.

  1. Configure the shell for the jenkins user by editing /etc/passwd/ and changing /bin/false to /bin/bash.

  2. su - jenkins. Note the jenkins user's home is /var/lib/jenkins

  3. ssh-keygen then cat .ssh/ and copy this key to your bitbucket account

  4. ssh to set the bitbucket ssh key in .ssh/known_hosts

Now you should be able to access bitbucket from Jenkins.

Reference link.