Continous Deployment from a GitHub repository using Jenkins (Simplified Method)

This is the simplest way of setting up continuous deployment with GitHub and Jenkins.

Caveats:

  • This is a one-way integration from GitHub → Jenkins to avoid having to set up GitHub authentication
  • Requires the GitHub repository to be public in order to allow checkouts

Jenkins Setup and Nginx Configuration

This setup is exactly the same as described in my main post on this topic.

GitHub Configuration

The simplified method of setting up a GitHub → Jenkins integration uses webhooks set up in the GitHub repositories.

Requirements (Jenkins Plugins):

  • GitHub Plugin

This option requires the least amount of setup on the GitHub side, but is also the most limited as it’s a one-way connection between GitHub and Jenkins. Simply open up your chosen repository, go to Settings → Webhooks, add a new webhook and set it up using the following settings;

GitHub Webhook Settings

Pushing to this repository will now send data to the payload URL, though additional setup is still required in Jenkins.

Note: The Payload URL is always the same. Jenkins automatically determines which pipeline(s) to start running based on the payload sent by GitHub.

Jenkins Configuration

1. Creating the Jenkins workflow

From the main Jenkins dashboard, select New Item, enter the GitHub repository name as the pipeline name and select Pipeline from the list (this may also work with a Multibranch Pipeline or other project types, but I have not personally tested it).

  1. Under General, enable ‘GitHub Project’ and paste the repository URL into the text box.
  2. Under Build Triggers, enable ‘GitHub hook trigger for GITScm polling’.
  3. Under Pipeline, choose ‘Pipeline script from SCM’, choose Git and paste the repository URL into this text box as well.

2. Adding the Jenkinsfile to the repository

This setup is exactly the same as described in my main post on this topic.

3. Building

In case the Jenkins pipeline does not start automatically after pushing to the GitHub repository, the build process may have to be run manually the first time around to properly initiate the webhook in Jenkins. Simply click ‘Build Now’ on the Jenkins project page and subsequent commits should build automatically.