Jenkins, bit bucket and Vagrant : cannot log in git

I want to integrate Jenkins to my Symfony 2 project, which is on a BitBucket repository.

I installed Jenkins on my Vagrant virtual machine, and then I configure a job.

So, in Source Code Management, I selected Git, and set the BitBucket SSH url in "Repository URL" (git@bitbucket.org:me/myproject.git). Then, logged as jenkins in my Vagrant box, I generated a SSH key, and I copied the id_rsa.pub in a new SSH Public Key in BitBucket. I added this key as credidential in my Jenkins job git configuration (with username as my BitBucket username).

Jenkins displays me this error when I try to build the project:

Started by user anonymous
Building in workspace /var/lib/jenkins/jobs/api/workspace
Fetching changes from the remote Git repository
Fetching upstream changes from git@bitbucket.org:myuser/myproject.git
using GIT_SSH to set credentials 
FATAL: Failed to fetch from git@bitbucket.org:myuser/myproject.git
hudson.plugins.git.GitException: Failed to fetch from git@bitbucket.org:myuser/myproject.git
    at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:625)
    at hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:847)
    at hudson.plugins.git.GitSCM.checkout(GitSCM.java:872)
    at hudson.model.AbstractProject.checkout(AbstractProject.java:1411)
    at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:651)
    at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:88)
    at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:560)
    at hudson.model.Run.execute(Run.java:1670)
    at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:46)
    at hudson.model.ResourceController.execute(ResourceController.java:88)
    at hudson.model.Executor.run(Executor.java:231)
Caused by: hudson.plugins.git.GitException: Command "git fetch --tags --progress git@bitbucket.org:myuser/myproject.git +refs/heads/*:refs/remotes/origin/*" returned status code 128:
stdout: 
stderr: Permission denied (publickey).
fatal: The remote end hung up unexpectedly

Do you have any idea of what is happening ? Thx !

Answers


Its because the remote server denied your pubic key. The logs are telling you that => stderr: Permission denied (publickey).

Do this, head to ~/.ssh Create a file called config and add the following, ensure the values reflect your personal setup.

Host bitbucket.org
    User myuser
    Hostname bitbucket.org
    IdentityFile /home/myuser/.ssh/id_rsa

Then re-run.


Need Your Help

How to resolve content presenter not displaying View?

wpf mvvm datatemplate tabcontrol contentpresenter

I've added a content presenter to my TabControl's data template, in order to display the correct view.

URL Rewriting: "index.php?id=5" to "home.html"

php url-rewriting

I'm developping a website using php and the "template.inc" class.