Jenkins CI, GitHub Webhooks, and Proxy Tunneling … oh my!

See the original post here.

In a recent lab session, I was challenged to get an automated build process set up using Jenkins on my local machine and a remote Git repo hosted on GitHub. While polling is a quick solution, it doesn’t scale well, and isn’t really the “pro” way to do it. It took a bit of research, a little trial and error, and one cool proxy service, but eventually my local build server was responding to pushes like a good CI soldier. Here’s how I did it.

TLDR;

Using the ngrok.io proxy service, you can create an internet facing tunnel between your local machine and a ngrok.io subdomain that points to a specific port on your local development machine. Using the created “subdomain” as the GitHub WebHook Payload URL, you can configure your local Jenkins instance to respond to GitHub repo changes and trigger builds or other automatic processes. READ MORE

PRELIMINARIES

You must have a running instance of Jenkins on your local machine. Preferably you have it running as a service so that you don’t have to keep up with turning it on and off. You can find plenty of tutorials for running Jenkins locally. My preferred method on the mac is to go the homebrew route and have it start at boot time as a service. Be sure to give Jenkins a designated port number that is not in use. It will default to 8080, but I find my nginx server likes that port, and so I’ve used an alternate port. You do what’s best for your setup.

Obviously you need a GitHub account. If you’re reading this and don’t have one … what are you waiting for. Go get one. SERIOUSLY!!! I’ll wait.

Finally you’ll need a proxy tunneling service to handle “exposing” your machine’s CI Server (Jenkins) to the web so that GitHub and talk to your local Jenkins, and vice-versa. There are a couple of providers out there. The one I will be using today is called ngrok.io. For small testing setups and single repo projects a free account should do the trick for proving to yourself that this will work. However, should you prefer to not have to reset your WebHook Payload URL (more on that in a moment) every time you get ready to be productive, you may opt for a paid membership. The lowest, at $5 per month (less if you pay for a full year) is pretty reasonable for what you get.

THE SETUP

Ok. Jenkins running locally. Check! GitHub account. Check! Proxy tunneling service (presumably ngrok.io … if not, you’re on your own on that part.) Check! So let’s get started.

OVERVIEW

The basic steps are as follows:

  1. Install Jenkins GitHub plugin
  2. Get ngrok up and running
  3. Configure Jenkins project
  4. Setup repo Webhook on GitHub
  5. Try it out

STEP 1 - INSTALL JENKINS GITHUB PLUGIN

The first thing you will need to do is

… Read more here.