Thursday, March 29, 2018

Webhooks for Github & Jenkins Integration - CI/CD Pipeline

In this post we will look at how we can use Webhooks feature of GitHub to Integrate Github with Jenkins.

Webhooks is a really a cool feature which helps to Integrate GitHub with Jenkins on the Push Events in Github.

There is a feature in Jenkins to Poll SCM for every configured number of Minutes/hours for change in the code. This way Jenkins is polling on SCM. Better/Preferred way is to use Webhooks for this integration where Whenever there is a Push in Github, a Payload is sent to Jenkins with Push/Commit details and New Pipeline is Initiated.

Pre Requsites
  1. Jenkins Server Installed on any IaaS or Local VM.
  2. Github Login Credentials
  3. Code Repository in GitHub with Sample Code. I have forked a code in my repo and added JenkinsFile which you can use as it is MyGitHubRepo.  Or You can also fork from Original Repo

Architecture Diagram



Lets Get Started

Configuring Jenkins

First Step in Configuring Jenkins is to Install GitHub Integration Plugin. Log into Jenkins Server and Click Manage Jenkins. Click Manage Plugins.

Click on Available Tab and Filter with Github.



Click Download Now & Install after Restart.

Create & Configure New Pipeline

Click Create New Item and Click Pipeline. Give a name to the new pipeline & Click OK.







Under General, Click on Github Project and give the url of GITHUB project. You can use below url if using my github forked project. https://github.com/rohanwalia/simple-node-js-react-npm-app



Under Build Triggers select : GitHub hook trigger for GITScm polling



Under Pipeline Section, Seclect Pipeline Script from SCM in Definition TAG. Need to use this if Jenkins file is in Code Repo.


Select GIT in SCM drop down.

In Repositories, provide the link to Repo Url : https://github.com/rohanwalia/simple-node-js-react-npm-app.git

Add credentials of GitHub.

Default Branch is Master Branch.

Script Path is name of Jenkinsfile which is same name in our repo.

Click Save and We are done with Jenkins Side of Configuration.

Configure Webhooks on GitHub

We will create a new Webhook.

Click on Settings inside the Repo.



Click Webhooks and Click Add Webhook.


In Payload URL Add : http://IpaddressofJenkinsServer:PORT/github-webhook/

Content Type : You May Select - application/json





Click Add Webhook.

Once completed, you will see below page with Webhook as Success. If there is error on the webhook, we need to analyze and fix the error.



We are All Done.

Lets Test now by changing / Pushing some code in our Code Repo. Added one comment on registerServiceWorker.js


Commit The Changes




Open Jenkins and Your Pipeline. It Kicks Off and Starts Executing/Building.



It shows the Comment added while Commit in GitHub.

Below is the Details of the Build Once Completed.



And we are all done.

Do let me know your views or comments on this post.

Thanks

11 comments:

  1. It is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful to me...

    DevOps Training in Pune

    DevOps Online Training

    ReplyDelete
  2. Really a great addition. I have read this marvelous post. Thanks for sharing information about it. I really like that. Thanks so lot for your convene. Best Wireless Charging for Google pixel 2 XL

    ReplyDelete
  3. This is really a very good blog and thanks for sharing it with the community!Keep Posting Many Blogs Like this.
    vito food oil dealers in chennai

    ReplyDelete
  4. As claimed by Stanford Medical, It is in fact the ONLY reason women in this country get to live 10 years longer and weigh 19 KG lighter than us.

    (And by the way, it has absolutely NOTHING to do with genetics or some secret-exercise and EVERYTHING around "how" they eat.)

    BTW, I said "HOW", not "what"...

    TAP on this link to uncover if this easy test can help you decipher your real weight loss potential

    ReplyDelete
  5. last month he share is herbal medicine in some medical hospital and now he is well recognize as one of the best in West Africa, you don’t have to be sad any more or share your tears any more on this virus when the cure have already be find in 2013 if you want to get in touch with him in private contact him on his email dr.chalaherbalhome@mail.com Or you can visit his website on https://
    drchalaherbalhome.godaddysites.com or https://mywa.link/dr.chalaherbalhome

    ReplyDelete
  6. This is nice blog
    https://highlineshoes.com/best-women-shoe-for-walking-on-concrete/

    ReplyDelete