Jenkins and GitHub integration

Both Jenkins and GitHub are very popular, so it couldn’t be a problem integrating them. It still might be a bit confusing if you’re doing it for the first time. That’s why I decided to spend a few minutes to show you guys how it can be done.

Jenkins master can be accessed through the URL different from the one specified in Jenkins configuration.

Why might we need this? Well, you probably want your Jenkins server to be publicly accessible (this is required for GitHub integration, by the way) and since it’s public you typically want to use an encrypted HTTPS connection.

Well, you can install nginx proxy to achieve this, but in this case you’ll have to maintain SSL certs, which obviously sucks, especially if you can use AWS Certificate Manager with AWS ELB.

Another reason to use different URL is to save your time. When you use Windows slaves via JNLP there’re well-known issues with both nginx and load balancers.

And the last but not least reason is that “LAN” connection between Jenkins master and slaves is still more secure and faster, so it’s preferable in most cases.

So let’s start implementing Jenkins and GitHub integration within these conditions!

First of all we need to have a GitHub account with public or private repo. The one I’m using is Developer and it’s a member of GitHub team, but it doesn’t really matter at all for integration.

Also I have Jenkins master with dozen of slaves and it has one link for internal usage and ELB-based link for external usage:

To set  Jenkins and GitHub integration you must have GitHub and Git plugins installed.

As soon as it’s done do not add any GitHub servers to Jenkins configuration section, just keep it blank:

Now create (or update current) Jenkins job and:

  1. Set GitHub project:

2. Set Source Control Repository URL and Credentials (it’s always better to use SSH):

3. Enable GitHub hook trigger for GITScm polling:

Well, you can ensure that you can execute job manually or via schedule and it will get sources from GitHub, but we want job to run after every single commit or pull request (it has commit as well).

To achieve this the only required action is to add Jenkins hook url:

.. and that’s it – as soon as the code is updated job will be queued automatically:

As you can see, no Webhooks are used:

What is also nice – if code was pushed while build was executing next build will be queued automatically (it’s not happening if you use Pull SCM schedule);

However, if code was changed several times only the first commit will be queued (regular webhooks have the same behaviour).

If you want to have more than one build in queue for the same job you have to add unique parameter to each build, this can be done easily with Random String Parameter Plugin :

I hope this info will be useful to you, and if you need any help feel free to use contact from on the main page.