How to Integrate Jenkins with GitHub | Cprime Blogs

Jenkins has become one of the most democratic tools to create CI/CD pipelines. There are many reasons for this, and one is the number of plugins and integrations that allow users to work with about any tool or platform out there. When you use a plugin, you only have to set some parameters like credentials. For case, you could use a plugin to deploy your infrastructure to AWS or Azure. Or, you could use the GitHub plugin to use Git as a depository for lotion or infrastructure code—you ’ ve issue forth here for this, I know .
Git is an all-important plugin that everyone working with Jenkins will need. You can get to the point of configuring a Jenkins job only once. then, all subsequent changes for the pitch grapevine can be done using a interpretation control condition system like Git. Are you wondering how to do this ? You ’ ve come to the right set ; I ’ ll show you how to integrate Jenkins with GitHub step by step .
Let ’ s beget started !

Prerequisites

A necessary prerequisite is to have a waiter with Jenkins up and running with the GitHub plugin. It ’ mho there if you installed the suggest plugins, but if you want to start from scratch, installing Jenkins international relations and security network ’ triiodothyronine complicated. You need to have Java 8 or 11 before you start. You ’ ll find more details in Jenkins docs about what it takes to install Jenkins in different platforms, like Linux or Windows. AWS or Azure market have an choice to instantiate a VM with Jenkins preinstalled. so, you have several options. Make sure you can log in with admin credentials to Jenkins and move on to the following section.

Create a Jenkins Job

You nowadays need to create a Jenkins occupation. To do so, chatter New Item ( 1 ). Or, if it ’ s a clean install, snap on create new jobs ( 2 ). Below is a screenshot of what it should look like :
Jenkins Github create new jobs
On the trace blind, type a diagnose for the job—for exemplar, tutorial ( 1 ). then, pick Pipeline ( 2 ) because we ’ ll create a job where the instructions are defined in a Jenkinsfile hosted in a GitHub repository. The reason I picked this type of Jenkins caper is because I want to configure it deoxyadenosine monophosphate minimally as possible. All the stimulate exercise is going to be defined as code in the Jenkinsfile. To finish, click OK ( 3 ) .
Jenkins Github Item Name

Configure the GitHub Hook Trigger

In the riddle you see now, scroll down a little to the Build Triggers incision. We ’ rhenium going to make sure that this Jenkins problem runs only when person pushes a exchange in the GitHub repo. You can configure other actions, like when person creates a pull request. But for simplicity ’ south sake, we ’ ll stick with the push action entirely. Of course, you can constantly run the job manually, but that ’ s not ideal. sol, choose the GitHub hook trigger for GITScm polling option .
Jenkins Github Hook Trigger

Use a GitHub Repository

Scroll down a bit more and you ’ ll see the Pipeline part, where we ’ ll tell Jenkins to use the GitHub repo as the beginning. In the Definition dropdown, choose Pipeline script from SCM to configure the repo. For the SCM dropdown, blame Git ( 1 ), and below, in the Repository URL, type ( or paste ) the broad GitHub repo URL. In my subject, the URL of my repo is https://github.com/christianhxc/jenkins-pipeline-tutorial.git ( 2 ) —you ’ ll have to use your own. You ’ ll do a variety belated in the repo to test that the integration with GitHub works. now, type the Script Path, which is going to be the path of the Jenkinsfile. In my case, the path is hello-world/Jenkinsfile ( 3 ). You can make a crotch of my repo if you want to follow the same steps in this tutorial .
Jenkins Github Repository URL
finally, chink on the Save button that appears at the buttocks of the screen .

Add a Webhook in GitHub

now, go to the GitHub project because it ’ second time to configure the webhook so that GitHub can trigger the Jenkins occupation after every energy in the repo. In your visualize, click on the Settings ( 1 ) check, then click Webhooks ( 2 ) from the leave panel. now, snap on the Add webhook ( 3 ) button at the right. hera ’ s a screenshot for reference point :
Jenkins Github Webhooks

You ’ ll see a newly human body. Make indisputable you have the compensate values, because this is the data GitHub will use to call your Jenkins server. The Jenkins end point you ’ ll practice must be publicly available over the internet. In my subject, the Jenkins URL is http://54.154.42.106:8080/, and I need to add github-webhook/ at the end. then, the Payload URL in my case is http://54.154.42.106:8080/github-webhook/ ( 1 ). adjacent, for the Content type dropdown, woof application/json ( 2 ). Leave the rest of the options as they are, with the Just the push event option selected. For ease, I said before that GitHub would call Jenkins entirely when there ’ s a push in the repo. If you want to configure other actions, you ’ ll have to select Let me select individual events, but for now, let ’ s keep it dim-witted. last, cluck on the green Add webhook clitoris .
Jenkins Github Webhook Button

If the webhook works, you ’ ll see a telling at the top say that the hook was successfully created, as in the screenshot below :
Jenkins Github Webhook Button Successful

Build the Jenkins Job Manually

now go rear to Jenkins, because we need to warm up the integration. To do then, cluck on the Build Now link from the left panel, and the Jenkins job will start running. This is a way of saying to Jenkins, “ Hey, this job has the GitHub trigger option configured. ” So, evening if this step doesn ’ t make common sense, do it, because I spent a few minutes figuring out why the consolidation with GitHub wasn ’ t working .
Build the Jenkins Job Manually

You should see a successful run of the subcontract, like this :
Jenkins Github Stage View

Change Something in the GitHub Repo

You finished the consolidation with GitHub in the former step. But because you and I are estimable citizens, let ’ s make certain that this integration works in full. therefore, go to the GitHub repository and change something, commit, and push. In my event, I added a new phase in the Jenkins pipeline to include more tests. Wait for a few seconds, and you should see another successful run of the job .
Jenkins Github Pipeline

If you go the logarithm for the moment time the job ran, you ’ ll notice something different at the beginning of the logs saying that GitHub started it, along with the username :
Jenkins Github Console Output

And that ’ s it—that ’ s how you integrate Jenkins with GitHub. Every time person pushes a change in the repo, this Jenkins problem will run .

GitHub Integrates Pretty Well With Jenkins

When you configure your CI/CD pipelines in the room we did in this tutorial, the team is more productive. There will be a time where the team will forget about Jenkins. Every new step, update, or cleaning will be done in the Jenkinsfile. We configured the job where the flow will be like this : Developers change code, GitHub triggers the Jenkins job, and Jenkins executes all the steps needed to deploy the new change.

If you want to learn more about Jenkins pipeline, you can take a look at the official doctor. Everything you need to know is there—the syntax, how to use it, how it works, and therefore on. Have playfulness, and constantly try to keep things clean and jerk and bare .

CI/CD Jumpstart Program

View Program
Christian Melendez

Christian Melendez
source : https://thefartiste.com
Category : Tech

About admin

I am the owner of the website thefartiste.com, my purpose is to bring all the most useful information to users.

Check Also

articlewriting1

How to Show Profile Picture Instead of Video in Zoom Meeting

Zoom is a democratic and utilitarian outside meet and television conferencing tool. however, not everyone …

Leave a Reply

Your email address will not be published.