Jenkins – Steps in using Github on windows

Posted: 10/01/2013 in Git, jenkins
Tags: ,

I had a great time figuring out how to checkout a GIT repository using jenkins under windows.
What caused me so much trouble was the ssh authentification.
Here are the steps a did to make it work.
I suppose you have a jenkins master machine and a slave building machine.

Install jenkins git plugins on your master machine

  • Git Client Plugin
  • Git Plugin
  • Git Server Plugin/li>
  • GitHub API Plugin
  • GitHub plugin
  • GitHub Pull Request Builder
  • Github Authentication plugin

Install git on your slave machine

On your slave machine install git command line application

http://git-scm.com/download/win

Add git to your Path system variable

  • Right-Click on My Computer
  • Click Advanced System Settings link from the left side column
  • Click Environment Variables in the bottom of the window
  • Then under System Variables look for the path variable and click edit
  • Add the pwd to git’s bin and cmd at the end of the string like this:
;C:\Program Files (x86)\Git\bin;C:\Program Files (x86)\Git\cmd

create a GIT_HOMEenvironement variable

In the same way create a variable named “GIT_HOME” pointing to your git bin folder:

C:\Program Files (x86)\Git\bin

Generate your private/public SSH keys with putty

First you need to download putty gen
Run it and click Generate button
Move your mouse around so that it can generate your keys using your mouse movements.
Once done create a folder on one of your drive called “.ssh”
Then you can save your private and public keys inside using the “Save public key” and “Save private key” buttons.
Don’t use credentials if you don’t want any console prompt when checking out with jenkins.
Note: When you save using those buttons it saves the data using putty own format.
What you want here is to get the key as an OpenSSH format.
For that you need to go in the menu bar “Conversions\Export OpenSSH key”. It will prompt for empty passphrase but it’s ok.
Then save the content into a file called something like id_rsa

Create git config file

On the “DRIVE:\.ssh” folder create a file called config (without any extensions)
Inside copy paste the following:

Host github_jenkins
	Hostname github.com
	User git
	IdentityFile D:\.ssh\id_rsa

Of course replace “D:\.ssh\id_rsa” by the location of your file containing your SSH key exported earlier.

Create a HOME environement variable

In the same way create a “HOME” environment variable pointing to the parent folder containing .ssh folder, (here “D:\“)

D:\

Configure Jenkins plugin

Go inside your jenkins system configuration page and in the git sub section make sure to point to your git binary folder as follow:
git_setup_1

Then look for your “GitHub Web Hook” sub section and make sure the “Manually manage hook URLs” is checked:
git_setup_2

Create GitHub token

Go to your gitHub web interface and inside your account settings, go to “Applications\Personal Access Tokens
Generate one and copy it.
Go back to your jenkins web interface, inside system configuration, go to the “GitHub pull requests builder
As “GitHub server api URL” put https://api.github.com if it’s not already there.
As “Access Token” place the key you have just generated.
Save your configuration.

Configure your Jenkins job

In your jenkins Job, go to your Source Code Management tab.
Click the “Git” option button.
on your repository address put

git@github_jenkins:MyRepositoryAddress.git

Note: github_jenkins is a hostname.
This hostname is written inside your [DRIVE]:\.ssh\config file after the “Host keyword”.
You can create as many hosts as you want and you can assign as many credentials as you have host names.

On the Branches to build text box you can enter the branch you want to build (origin/develop for example)

Alternatives

Here are some alternative links:

Leave a comment