How to Integrate GitHub with Jenkins

Continuous Integration (CI) and Continuous Development (CD) are the two integral and important components of automatic deployment to the cloud. For opting out the tasks and to avoid the daily grind of deployment, continuous integration is the only solution. It can be described as a project management tool that helps to integrate codes in a shared repository. To make the work really easy, we resort to GitHub integration with Jenkins.

How does the integration between GitHub & Jenkins help?

Continuous Integration is the way to bypass the monotonous and repetitive tasks of developing, testing and deploying codes. Now, Jenkins, an open-sourced tool, helps to deploy the new builds automatically after testing them against a pre-automated build. Thus, it helps the project team to detect errors at an early stage. Jenkins is able to perform continuous testing with the help of quality check tools such as Selenium, JUnit. If everything is fine, the code is deployed by Jenkins for production. Else, a notification is shown stating the build has failed and changes are to be made for rectifying the bugs or errors.

The steps to do successful GitHub integration with Jenkins:

To expedite the deployment process, it is important to understand how Jenkins can be integrated to GitHub. But before that, one needs to set up Jenkins and have to have the public IP of the server where Jenkins is installed or being set up. Below are the steps for GitHub integration with Jenkins. Just follow the sequence and it will be over before you know it.

I. Configure GitHub:

The first and foremost thing before you start the process, you need to have your own GitHub repo ready. It is a repository of codes that provides a common platform to multiple software developers to upload and retrieve the updated code to be deployed. If, by any chance, you don’t have your own repo you can always fork LovesCloud’s GitHub repo.

https://github.com/LovesCloud/jenkinsgithubintegrationdemo

LovesCloud, a specialized clouds and DevOps company would be happy to help your company do that. Fork the repo in your own GitHub account and proceed further.

  • Open Jenkins in the browser and open GitHub.
  • Navigate to Git repo.
  • Now, navigate to the settings of the repository.
  • Select Webhook.
  • Click on ‘Add Webhook.
  • Now this is the most important part – enter the Payload URL— http://:8080/github-webhook/ as shown below:-
  • Click to save Webhook and you are done with the part of configuring GitHub.

II. Integrate Jenkins:

  • Go back to the browser tab where Jenkins is already kept open.
  • Find out the ‘New Item’ option in the Jenkins dashboard and click on it.
  • You have to give the ‘New Item’ a name. This can be anything.
    For example _Githubwebhookintegration.
  • Next step is to select the ‘Freestyle Project’ option.
  • Click ‘OK’ to confirm and proceed further.
  • Now, you will find a section named ‘Source Code Management,’ under which, you will have to select Git radio button. It asks you to enter a URL. Here, you will have to enter your repository URL which contains your forked repo.
    Please take note: you have to use your own forked repo. You can copy the URL from the address bar of the browser where your GitHub repo is opened.
  • Now, go to ‘Build Triggers Section’ and select “GitHub Webhook trigger for GITscm polling” checkbox.
  • Next, click ‘Save’ and move on.
  • Again, go to GitHub. Being the owner of the Git repo, you can now edit a file and make the changes.
  • To check if everything is okay, go to Jenkins on the browser and you can observe that the build has been automatically triggered as you had committed the file in GitHub in your own repo.
  • Click on the ‘Latest triggered build number’ to check and confirm for the build number.
  • You can also check the console output afterward.

That was quite a joyride, wasn’t it? Now that you have successfully integrated GitHub to Jenkins, your Jenkins job will automatically be triggered as soon as, you being the developer, commit the code in Git.

LovesCloud has gained expertise in deploying and maintaining Kubernetes across different cloud providers. It has successfully managed services like AWS EKS, Azure AKS, GCP GKE, and delivered turnkey solutions like KOPS and custom HA Kubernetes deployments to various enterprises. Reach to us for Github assistance at …..@loves.cloud.