16
votes

At moment I'm trying to create connection from jenkins to my bitbucket repository, using the git plugin that I've installed in jenkins.

When I enter to the repository URL, I get the following message notification shown in the figure:

"Failed to connect to repository : Command "ls-remote -h [email protected]:safe2school-ondemand/s2s-android-padres.git HEAD" returned status code 128: stdout: stderr: Permission denied (publickey). fatal: The remote end hung up unexpectedly"

Trying connect to bitbucket repo from jenkins through git

I've install jenkins on apache tomcat container, which is located in a path /srv/apache-tomcat

In the system I have a root ssh-key and I add this key to bitbucket. I appreciate your support :)

2
did you set up the ssh keys for the Jenkins user? stackoverflow.com/questions/13890500/…KeepCalmAndCarryOn
Note that credentials support is built-in to the git plugin now. The screenshot shows that you've chosen no credentials for this repo.Christopher Orr
Christopher, what credentials may I have add, In this field .. are the username and password of my bitbucket account. I don't think so..bgarcial
If you don't want to go the user password root, I did have a similar issue that I solved and posted an answer for in stackoverflow.com/questions/34420362/… The TLDR; presuming your keys are all set up correctly, try removing the ".git" from the end of the repo url.Jeff Richards

2 Answers

28
votes

You can try with user-password authentication credential, this is the alternative way that this plugin gives us.

  1. Click 'Add' button.

enter image description here

  1. Select "User with password" in Kind input.
  2. Add bitbucket account credential.

enter image description here

  1. Enter bitbucket repo url using 'https' protocol.

enter image description here

Finally, the absence of errors (like red messages under repo url input) means that the process had success.

1
votes

In addition to @geoom answer, 2FA users can use "app passwords" for the credentials

App passwords are substitute passwords for a user account which you can use for scripts and integrating tools to avoid putting your real password into configuration files.

App passwords are designed to be used for a single purpose with limited permissions, so they don't require two-step verification (2SV). This means app passwords can be used by users with 2SV make API calls to their Bitbucket account, and to integrate Bitbucket with other tools like Sourcetree and Bamboo.