Posted on

Jenkins, Windows Server 2008 R2 and Git with SSH

The team I’m on have been using Hudson for our builds for quite a while and really like it. A while back, something went terribly wrong and Hudson, well, let’s just say he passed away. We tried and tried to bring him back but after a week of doing all we could, we had to call the time of death.

This was a new beginning though, because we could move over to Jenkins and be one of the modern cool kids. Yeah, not quite as plug-and-play as we hoped. We spent many days trying to get it to work. Through the process, we hit about every error it can spit out. I’ll try to detail what we ran into and how we solved it (to the best of my memory) in another post, if I have the time. In this post, I’ll just summarize the final solution in hopes it will help someone else out there.

Our environment

We’re running Windows 2008 R2 Datacenter SP1 on a virtual machine in Amazons Cloud. Our repository is hosted at After looking around the web for solutions to the errors I ran into, I wished we used GitHub since it seems like EVERYONE else out there does. That’s what most of the solutions are for. Luckily, codesion has enough on their site for me to wrap my head around what I needed to do. We have Git Bash installed on the server.

Install Jenkins

Do everything under the same account from now on, as long as you’re getting Jenkins all configured. Let’s say you’ve created a unique account for Jenkins so your team can all log in to the same account when working on Jenkins. That username is jenkinsuser for the examples here. Once that user is all set up, you can install the Jenkins application. This part is pretty straight forward so I won’t go into detail.

Set the HOME environment variable

Make sure the HOME environment variable is set to the jenkinsuser User directory. I’m actually not entirely sure it wasn’t in our case, but I saw some posts that stated it doesn’t do it automatically.

Create SSH Keys

This was the biggest stumbling block for me. We spent forever trying to get it to authenticate correctly. So, to summarize, you start Git Bash and follow the instructions here: Don’t set a passphrase! It will save you time and frustration later.

In that github link, it talks about supplying your public SSH key. In codesion, this is under My Settings > SSH Keys. Then, go to the projects tab and click on the project you’re going to be building with Jenkins. On the right, is a services section where you can expand Git and see the ssh url. Copy this down because you’ll need it for Jenkins. It will probably say something like ssh://

Configure Jenkins

In Jenkins, you can now set up your project to connect to your git repo for builds. Under the project configuration, there will be a Source Code Management section. Choose Git and paste the ssh url from earlier into the Repository URL field. In the Build section, I just added a Windows batch command of echo HEY, I’M BUILDING, FINALLY!... That’s just so you can see that it got to that point and all was well. If you’re lucky, you can click SAVE and then build now and it will work. Check the Console of the build to see errors.

I wasn’t lucky. I ran into some other issues. The first, was that when I went to Manage Jenkins > Configure Jenkins, then scrolled down to the Git section, it had git.exe as the path to Git executable. I had to change this to the full path, despite what one blog post cautioned against.

The final one, that may have been what fixed many of the other issues, was to install the Jenkins git plugin instead of the Hudson version it comes with. Not sure why that isn’t default, but whatever. You can go to Manage Jenkins > Manage Plugins and choose the Installed tab. You should see your Git plugin there. Uncheck the check box to disable it. Restart Jenkins so it’s happy. Then, go here: to download the latest git.hpi file.

Go back to Jenkins then and to the Manage Plugins area, to the Advanced tab. There you’ll see where you can upload the file you just downloaded. Once it’s installed, you’ll have to back to that page, to the Installed tab and enable the plugin. Then back to the configure page for your project and enter the ssh url into the Git section again. This fixed it for me.

I hope this helps someone else out there. I’d love to save someone days or weeks of banging their head against a wall.