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 firstname.lastname@example.org:GenRocket/GenRocket.git hudson.plugins.git.GitException: Could not clone email@example.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 firstname.lastname@example.org: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.
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 email@example.com