How to use git with Jenkins on Windows

The basic idea

You have to install git and get it into the path of the user account running Jenkins. We’ll take advantage of Github for Windows’ installation of git to do this.

How I did it

  1. Ensure that the Jenkins service is running under an account that you can actually log into. We’ll refer to this as JenkinsServiceAccount from here on.
  2. Login to the box with the JenkinsServiceAccount.
  3. Install Github for Windows. When it’s finished, just close the app if it comes up.
  4. There’ll be a shortcut to Git Shell on the desktop, right click that and click Open File Location.
  5. In the folder that opens, you’ll see a file named shell.ps1. Open it in your favorite text editor.
  6. Find the line where $env:github_git is set. Mine was set to:
    C:\Users\JenkinsServiceAccount\AppData\Local\GitHub\PortableGit_fed20eba68b3e238e49a47cdfed0a45783d93651
  7. You need to add three subfolders of that folder to the system PATH (via System Properties -> Environment Variables -> System Variables). What I added looks like this:
    C:\Users\JenkinsServiceAccount\AppData\Local\GitHub\PortableGit_fed20eba68b3e238e49a47cdfed0a45783d93651\cmd;C:\Users\JenkinsServiceAccount\AppData\Local\GitHub\PortableGit_fed20eba68b3e238e49a47cdfed0a45783d93651\bin;C:\Users\JenkinsServiceAccount\AppData\Local\GitHub\PortableGit_fed20eba68b3e238e49a47cdfed0a45783d93651\mingw\bin
  8. Restart the Jenkins service and it should now be able to use git.

Probable Gotcha

The path to PortableGit looks like it has a changeset in the folder name which means that if you update Github for Windows, that path might change. This is dumb, however, I don’t believe Github for Windows will update if you never open it. So, never open it.

This entry was posted in Uncategorized and tagged , , , , , . Bookmark the permalink.