Configuring webhook in github, gitlab and bitbucket

Configuring webhook github
step1: Open Github repository.
step2: Go to “settings” and then to “hooks”.
step3: Click the “Add webhook” button.
step4: Fill in the form, as shown in the image below. For the payload URL, provide your Jenkins URL and the GitHub webhook path at the end of the URL — https://${jenkins_url}/github-webhook/. You can disable SSL verifications if you don’t have a valid SSL cert for our Jenkins server. Finally, choose the option “Calling the webhook only for push events.” (This actually depends on what you are trying to do. You can change this by selecting other options).


Click on “Add webhook”
Now let’s see how to use this webhook in Jenkins.
*Go to Manage Jenkins -> Configure System
*Scroll down and you will find the GitHub Pull Requests checkbox. In the Published Jenkins URL, add the repository link
*Click on "Save."

Now go to the Jenkins pipeline and select "GitHub hook trigger for GITScm polling."

we can add a webhook to our job and ensure that every time a developer commits a code to GitHub, our build will be triggered

Configuring webhook Gitlab
GitLab Configuration
 create a user and access token go to Profile Settings -> Access Tokens. Over there create a new user named “jenkin-user”. Now create a personal access token and save it. In the Scopes, field tick the checkbox

Copy the access token and save it somewhere, because it won’t be visible for the second time

Jenkins Configuration
1.Add Gitlab credentials to Jenkins
In the Jenkins’s System credentials add a new credential of the type GitLab API token. Paste the API token copied earlier in the ‘API Token’ field and save them.

webhook configuration
Create a new GitLab project or choose an existing one. Then, go to Project-> Integrations -> Jenkins CI. Enter the Jenkins project URL in the given ‘URL’ field, select the trigger events from the list and save. A new webhook will be added accordingly.

If we push a commit to the repository, we should see the Jenkins job start running.

Bitbucket webhook configuration

Whenever we commit our changes or push something to our codebase or remote repository, our build on Jenkins should start, and that we can automate using the webhooks integration.
Similar steps we can follow if we are using GitHub rather than BitBucket for our codebase. The only URL will alter that will see in the next section.

Integration with BitBucket
Log in to Jenkins Server and make necessary steps to configure your security inside Global security, install respective plug-in’s and then create a job by setting the  Project and click the checkbox of “Build when a change is pushed to BitBucket” and save the project.

Then go to the Bitbucket repository, Settings > Webhooks > Add Webhook > Add name as anything and URL as https://${jenkins_url}/bitbucket-hook/


Then we are done. Make whatever changes in our code that will pull into the repository that will get reflected onto the Jenkins Server and start the build process on the server.

Recent Comments

No comments

Leave a Comment