5
votes

I am trying to connect Jenkins to a private BitBucket repository.

I have a set (both id_rsa and id_rsa.pub) of SSH keys generated at /var/lib/jenkins/.ssh. I've copied the id_rsa.pub key and pasted it in the deploy keys section of my BitBucket repository. Similarly, running the command git ls-remote -h [email protected]:user/project.git has a valid return and has been added to known_hosts.

What might be causing my Jenkins to not connect in the git Source Code Management section of Jenkins? The error returned is:

Failed to connect to repository : Command "git -c core.askpass=true ls-remote -h https://[email protected]/user/project.git HEAD" returned status code 128: stdout: stderr: remote: Invalid username or password. If you log in via a third party service you must ensure you have an account password set in your account profile. fatal: Authentication failed for 'https://[email protected]/user/project.git/'

I also tried ssh -Tv [email protected] as per this doc from Atlassian regarding troubleshooting SSH issues. The return states at that:

This deploy key has read access to the following repositories:

user/project: Jenkins -- jenkins@ip-xxx-xx-xx-xxx

1
So I made a dumb mistake and used https://[email protected]/user/project.git for Repository URL instead of [email protected]:user/project.git facepalm Changing it to the latter works, without the need for filling out credentials (assuming SSH has been set up successfully).Xenyal
Please, add your comment as solution and mark this as solved :)Jose Camacho
you ought to add this as the anser @Xenyal . I made the same mistake with GitHub.angryip
JoSSI and @angryip Thanks for bringing this up. I've added it as the accepted solution.Xenyal

1 Answers

4
votes

For the Project Repository field that Jenkins' Git Plugin provides, it seems that one of their examples shown in their home page for that field (specifically, https://[email protected]/user/project.git) does not work. It might either be a case of plugin version, or how BitBucket might be configured differently than GitHub, of which their documentation uses for examples.

What did work for me however, was using the git address of the following format:

[email protected]:user/project.git