Skip to main content

CONTINUOUS INTEGRATION WITH GIT AND JENKINS USING GIT WEBHOOK

Assume we have jenkins and maven running on same server.Consider that we want to run a job each time when developer is commiting a code to our git hub repository. For that we can make use of webhook feature provided by git.

Assume that we have installed github plugin and maven integration plugin. First go to our jenkins server. From Dashboard > New item. Now give the name of project we want ( Here we are giving webhook-test as project name).Here we will go with free style project. So Select freestyle project and click ok.



Here select github project.Give the github url where our code is present



Now go to source code management. Select Git. Here we want to give  repository url.For that go to repository( new ) in our github account and copy url from there.


As it is a public repository we don't want to give credentials.By default jenkins will take master branch.If we want to change it change it under Branches to build.
 Now under build triggers secion select Github hook trigger for GITScm polling. This will make sure that new job is executed when any change occurs to our github repository.

Now under Build section select invoke top level maven target. Give clean package command.Then click save.
Now we want to configure webhook in our github repository. Go to our github repository. Under settings > Webhooks> Add webhooks

  

Here under payload URL give http://public_url_or_ip_of_jenkins_server/github-webhook. Here github-webhook means we are telling the jenkins to route the request to github plugin. Under Content type select application/json.Give Secret as blank since we have not configured any secret id on our jenkins server. Under which event you like to trigger this webhook? select just push event.Then tick Active and click Add webhook



.

Now to test wheather jenkins is running the job on making new commit jst edit the readme.md file in our github repository and commit it.Now refresh your jenkins window we can see new build running.