Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins Build Using Git with Deploy Key

I added the git plugin to Jenkins. I've generated a public key as the jenkins user on the build server. I added this key as a Deploy Key to github. I've added the global git properties with the jenkins name and email and the email matches what is at the end of the public key.

When Jenkins tries to pull from the git repository (hosted at Github) I get the following:

Started by user anonymous
Building in workspace /var/lib/jenkins/jobs/Test Deployment/workspace
Checkout:workspace / /var/lib/jenkins/jobs/Test Deployment/workspace - hudson.remoting.LocalChannel@9ba3afe
Using strategy: Default
Cloning the remote Git repository
Cloning repository origin
ERROR: Error cloning remote repo 'origin' : Could not clone [email protected]:GenRocket/GenRocket.git
hudson.plugins.git.GitException: Could not clone [email protected]:GenRocket/GenRocket.git
    at hudson.plugins.git.GitAPI.clone(GitAPI.java:245)
    at hudson.plugins.git.GitSCM$2.invoke(GitSCM.java:1121)
    at hudson.plugins.git.GitSCM$2.invoke(GitSCM.java:1063)
    at hudson.FilePath.act(FilePath.java:839)
    at hudson.FilePath.act(FilePath.java:821)
    at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1063)
    at hudson.model.AbstractProject.checkout(AbstractProject.java:1218)
    at hudson.model.AbstractBuild$AbstractRunner.checkout(AbstractBuild.java:586)
    at hudson.model.AbstractBuild$AbstractRunner.run(AbstractBuild.java:475)
    at hudson.model.Run.run(Run.java:1438)
    at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:46)
    at hudson.model.ResourceController.execute(ResourceController.java:88)
    at hudson.model.Executor.run(Executor.java:239)
Caused by: hudson.plugins.git.GitException: Command "git clone --progress -o origin [email protected]:GenRocket/GenRocket.git /var/lib/jenkins/jobs/Test Deployment/workspace" returned status code 128:
stdout: Cloning into /var/lib/jenkins/jobs/Test Deployment/workspace...

stderr: Host key verification failed.
fatal: The remote end hung up unexpectedly

Not sure what the issue is or what I've forgotten to do with regards to configuration. Any help is appreciated. Let me know if you need more details.

like image 590
Gregg Avatar asked Jun 14 '12 20:06

Gregg


People also ask

How do I deploy git code to Jenkins?

How does Jenkins integrate with Git? Go to Jenkins dashboard, click on “Manage Jenkins.” Now follow these steps- Manage Plugins -> 'Available' tab -> Enter Git in search bar and filter -> Install required plugin. After the installation, all you need to do is click on “Configure System” and go to the 'GitHub' section.

What is the key used for deploying job in Jenkins?

We can use SSH-KEY mapping GIT server and CI server together. But that means we must use same SSH-KEY in different projects and some guys can run command “commit” and “push “commit code to GIT repository through CI server.

Where do I put ssh keys in Jenkins?

Add SSH Key inside JenkinsIn the dropdown, select 'SSH username with private key' and then give a name for it. Copy the private key from the Jenkins server. Now you can clone any git repo in this Jenkins instance. You do not need to provide the credentials while configuring the job in Jenkins.


2 Answers

For the permission denied error, you need to ensure that you are using the key that you have created. To do this, create a file called "config" in your ~/.ssh directory. Populate the config file with the following:

  • HostName github.com
  • User git
  • IdentityFile ~/.ssh/id_rsa
  • IdentitiesOnly yes

Just ensure that the IdentityFile value points to your key. :)

Verify with the following: ssh -vT [email protected]

like image 169
jboles Avatar answered Oct 14 '22 12:10

jboles


Try adding github to the .ssh/known_hosts file of the jenkins user. If you manually try to clone as the jenkins user, it should prompt you to add github.com as a known host. Once you do that, jenkins should be able to verify the host key when doing builds.

like image 40
kjw0188 Avatar answered Oct 14 '22 12:10

kjw0188