Wednesday, April 27, 2011

Trials and Tribulations of getting Jenkins on Windows pulling from GitHub

I spent the better part of the last two days getting a Jenkins build which runs on a Windows 2008 server to pull from GitHub. You might think, “Wow, Todd really must be an (idiot|rube|dolt|moron|manager) to need 2 days to setup a CI server”. Well, you might be right, but even a simpleton like myself can google the shit out of a problem and come up with some type of frankensteined solution in a day or less. Apparently though, I am one of 5 people on this planet to actually use the cluster of Jenkins/Windows/Github. In case there are more of you out there, I thought I would try to spell out exactly what I did so that you don’t have to suffer (and so that when I forget how I got this thing to work and the server needs to be rebuilt in a year I can do it).

Step 0: I’m assuming you already have a Windows server with Jenkins up and running on it. I’m also going to assume that you installed it as a service. if you aren’t there yet, follow the instructions here: https://wiki.jenkins-ci.org/display/JENKINS/Installing+Jenkins+as+a+Windows+service

Step 1: Install yourself some msysgit from here: http://code.google.com/p/msysgit/

Step 2:  Head to Manage Plugins from the main Jenkins menu, select the Git plugin from the list of available plugins, and install that puppy. You’ll need to restart the service for this to take effect.

Step 3: I had to explicitly configure Jenkins to use the git.cmd instead of git.exe. I believe this properly sets the HOME variable so that your ssh and netrc files can be located when Jenkins fires off a build. From the Manage Jenkins link at the top level, you should have the option of adding a git installation. Provide the full path to the <GIT_HOME>/cmd/git.cmd file in this line as shown here:

image

Step 4: Generate and upload an ssh key for your github account. Make sure you are logged in as the same user that the Jenkins service runs under. Good instructions here: http://help.github.com/win-set-up-git/

Step 5: Configure a _netrc file and store it in the home directory of the user Jenkins runs under. My _netrc file looks like this:

machine github.com
login pillarci
password notmypassword


Step 6: Set an environment variable for HTTPS_PROXY if you have a firewall.



Step 7: Test that you can pull down from the command line. Given your repository name, you should be able to go to the command line and run something like



git clone https://github.com/SomeOrg/SomeRepo.git


Step 8: Configure your build on Jenkins. Please note that the repository name should not have the username in it and it should be using the https url, not the git url. Something like this:



image



Step 9: Kick that build off and pray. At this step I had a number of obtuse error messages and hung builds. If either of those instances occur with you, proceed to steps 10-47.



Possible Step 10 – 47: Check for a .git folder in your workspace without a sibling directory containing your repo. Nuke it if so and retry the build.



That should be all you need to get up and running. Again, I had some issues, many of which were the fault of the user, many due to the lack of info out on the internets. Luckily I work with a really smart guy named Justin Searls and he had already laid a bunch of this pavement for me. Happy GitHubbing!