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:

  • Is there any difference between `git branch -Dr …` vs. deleting the file directly in refs/remotes/origin?
  • Octopress - source branch suddenly is pushing to master
  • How do I clone an empty bare repository with Ansible git module?
  • Python: catch git error
  • How to separate changes from master into another branch without overwriting history?
  • Undo git rebase to save local changes
  • 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 git@github.com:GenRocket/GenRocket.git
    hudson.plugins.git.GitException: Could not clone git@github.com: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 git@github.com: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.

  • Getting a list of commits along with the commit message and hash in Git
  • Git commit on Windows (Cygwin) is broken.
  • git undo deletes but preserve new work
  • Is it possible to have multiple HEADs within a single git repository?
  • Using Git with Eclipse causing lots of errors
  • invalid credentials - LDAP access error in git community edition
  • 2 Solutions collect form web for “Jenkins Build Using Git with Deploy Key”

    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.

    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 git@github.com

    Git Baby is a git and github fan, let's start git clone.