Create Webhook for Jenkins using Github

Tiempo de lectura: 3 minutos

Reading time: 3 minutes

Hello, today we are going to learn how to create a Webhook to automatically deploy with Jenkins using Github.

First, let’s go to our Jenkins and settings.

We need to install the Generic Webhook Trigger plugin, which is compatible with Github.

Once installed, go to your Jenkins Job > Configuration and Build Triggers.

Choose Generic Webhook Trigger:

Replace Jenkins_URL with the URL of your Jenkins.

Now we need to create a token to identify the project:

Reading time: 3 minutes

Hello, today we are going to learn how to create a Webhook to automatically deploy with Jenkins using Github.

First, let’s go to our Jenkins and settings.

We need to install the Generic Webhook Trigger plugin, which is compatible with Github.

Once installed, go to your Jenkins Job > Configuration and Build Triggers.

Choose Generic Webhook Trigger:

Replace Jenkins_URL with the URL of your Jenkins.

Now we need to create a token to identify the project:

We can use, for example, (or generate a random token):

PROJECT_NAME

The URL will be:

https://jenkins.dev.mgbiomed.es/generic-webhook-trigger/invoke?token=PROJECT_NAME

Now let’s go to our project on Github.

Go to Settings:

Now go to Webhooks:

Create a new webhook by clicking on Add webhook:

Now go to your Jenkins Job and click on Config:

Now copy the webhook with the token we created:

https://jenkins.dev.mgbiomed.es/generic-webhook-trigger/invoke?token=PROJECT_NAME

Inside Payload URL:

Make sure to select application/json for branch filtering to work.

Go back to Jenkins and click on Advanced within the previous webhook section.

No need to specify Secret Token as we included it in our call with the created token.

Enable SSL verification if your Jenkins server works with HTTPS.

I have also selected “Let me select individual events” to allow selecting which events will invoke the created Webhook.

For example, Pushes:

You can also choose “Just the push event” if you only want to invoke it on the Push event.

If we go back to Jenkins, we can choose to only invoke it when we make changes to the specified branch within Post content parameters:

In the Variable name, enter “ref”:

Leave Value Filter and Default Value empty.

Now, go to Optional filter and create the expression:

^refs/heads/{branch_name}$

Replace {branch_name} with the name of the branch you want to filter.

Add the following in Text (the variable we are testing):

$ref

As shown in the image:

Leave a Comment