
How to integrate Jenkins with GitHub
This article will show you how to integrate Jenkins with Github. Jenkins is an open-source automation software that aids in the building, testing and deploying of software products. Any source can be easily fetched using Git Plugin from the Git repository accessible via the Jenkins build node. This skill is an essential one that will be tested in the Jenkins Certification exam.
Git is an open-source version management system. It is one of the most used tools by developers to manage their code. DevOps engineers who have experience with Jenkins are highly sought after. Let’s learn more about Jenkins and GitHub integration.
Prerequisites
Before you proceed to the steps to integrate Jenkins with GitHub, please ensure that you meet the following requirements.
Server with Jenkins up and running
Install the GitHub plugin on the Jenkins Server
GitHub Account
Step 1: Create a Jenkins job
Let’s begin by creating a new Jenkins Job. Click on “New Item”, choose the “Pipeline”, and click on the OK.
Step 2: Configure GitHub Hook Trigger
Scroll down to the section “Build Triggers” on the configuration page and choose the option “GitHub hook trigger GITScm polling”.
Note: This pipeline will be set up to trigger whenever a Github commit occurs.
Step 3: Create a GitHub repository
Step 4: Connect a GitHub repository
Scroll down to “Pipeline”. We will configure Jenkins so that it uses GitHub as its source. Under the definition option, select “Pipeline script from SCM”.
Select “git” from the SCM dropdown
In the repository URL section paste the URL of the GitHub repository you wish to use for this pipeline. In my case, I am using a repository that I created in the previous step.
Click on Save and type the Jenkinsfile path.
Step 5: Adding a WebHook to GitHub
Log in to GitHub to access the repository you connected in the previous step.
Click on “WebHooks”, then click on the “Add WebHooks” button.
This page will configure Jenkins URL to allow GitHub to call Jenkins for the actions. In the “Payload URL” section, enter the Jenkins server URL that is accessible over the internet.
Select the option “application/json” from the dropdown menu. Click on Add Webhook to close the remaining fields. The message will inform you that the Webhook was created.
Step 6: Manually building Jenkins jobs
Now, go back to Jenkins dashboard and click the Job we have created. Click on “Build Now” on the left.
Step 7: Trigger Build using GitHub Commit
You can add a new commit to your GitHub repository by making any changes. Within a few seconds, the Jenkins dashboard will show the build is running.
Summary
We hope you found this Jenkins tutorial helpful and that you now understand the importance of GitHub and Jenkins together. For those who are preparing to take the Jenkins certification exam, you can continue learning about Jenkins.