Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure Hudson and git plugin with an SSH key

I've got Hudson (continuous integration system) with the git plugin running on a Tomcat Windows Service. msysgit is installed and the msysgit bin dir is in the path. PuTTY/Pageant/plink are installed and msysgit is configured to use them.

When I run a job that attempts to clone the git repository I get the following error:

$ git clone -o origin git@hostname:project.git "e:\HUDSON_HOME\jobs\Project Trunk\workspace" 
ERROR: Error cloning remote repo 'origin' : Could not clone git@hostname:project.git 
ERROR: Cause: Error performing git clone -o origin git@hostname:project.git e:\HUDSON_HOME\jobs\Project Trunk\workspace 
Trying next repository 
ERROR: Could not clone from a repository 
FATAL: Could not clone 
hudson.plugins.git.GitException: Could not clone 
  1. Running git clone -o origin git@hostname:project.git "e:\HUDSON_HOME\jobs\Project Trunk\workspace" from the command line works without error.
  2. I've confirmed that my issue is not the same as Hudson git clone error because git is in the path and I don't get any error about the git executable on Hudson's Configure System page.

This leads me to believe that the problem is that the user who owns the Tomcat/Hudson Windows service (Local System) has no SSH key set up to be able to clone the git repository.

My question is, how can I set things up so that the git plugin/msysgit know to use a particular SSH key when trying to clone? I don't think Pageant will work because the Tomcat service is running as the "Local System" user, but I may be wrong. I have tried setting Pageant up as a service (using runassvc.exe), passing the appropriate key, and having it run as "Local System". The Tomcat/Hudson service doesn't seem to be able to see the key from the pageant service. Are there any other techniques for setting up a key?

Thanks.

EDIT: The discussion on http://n4.nabble.com/Hudson-with-git-and-ssh-td375633.html shows that someone else had a similar question. ssh-agent was suggested and this tool does come with msysgit but I'm not sure how to use it in conjunction with the Hudson service. Still, good clue if anyone can fill in the gaps. Thanks to Peter for the comment with the link.

Also, the discussion on http://n4.nabble.com/questions-about-git-and-github-plug-ins-td383420.html starts off with the same question. I'm trying to resurrect that thread.

like image 258
jlpp Avatar asked Mar 15 '10 14:03

jlpp


People also ask

Can I use the same SSH key for GitHub and Gitlab?

The first question you can ask yourself is can you have the same ssh key for both Github and Gitlab? The answer is yes but it is not advisable. The best answer is that you should set one ssh key for Github and another one for Gitlab. The first thing to do is install Git if you haven't.

How do I create a SSH key for GitHub and Jenkins?

Configure SSH Key for GitHub Project Once logged in to GitHub, you need to go to the sample repository on which you have access. Go to repository settings -> Deploy keys -> Add deploy key: Give a name such as 'Jenkins User' and add the key. You may select 'allow write access' as well.


1 Answers

Another important note for windows (which I want to attach to this answer because I found this question very quickly, but found this additional detail I needed only after hours of searching):

Git wants the %HOME% environment variable set to your user's directory (I.E. C:\Documents and Settings\hudsonuser)... that's how it knows to look in there for the .ssh dir with the key files!

I found this out here on server fault (but don't have enough reputation there to upvote it).

like image 139
Eggplant Jeff Avatar answered Oct 16 '22 06:10

Eggplant Jeff