In today's article, I will talk about how to set up a GitHub webhook for Jenkins. This is really useful when you need to trigger a Jenkins job when a new commit has been pushed to your GitHub repository. Tgithub webhook secret, his method is really useful to automate your CI/CD pipeline and enhance the efficiency of building, testing, and deploying your code. Let's get started.

Prerequisites

  • Jenkins Server
  • If you don't have a Jenkins server, you can follow this article to set up your own Jenkins server.
  • GitHub Repository
  • Generate Jenkins token

    Firstly, we need to create a token for GitHub to authenticate with Jenkins. To do it you should follow the steps below.

  • Navigate to your Jenkins Dashboard

  • Click on your username on the top right corner

  • alt text
  • Click on Configure

  • alt text
  • Click on Add new token

  • alt text
  • Give a name for your token and click on Generate

  • alt text
  • Make sure to copy the generated tokekn to secure place
  • Setting Up GitHub Webhook

  • Navigate to your GitHub repository
  • You need to navigate to project which you want to set up the webhook
  • Click on Settings

  • alt text
  • Click on Webhooks

  • alt text
  • Click on Add webhook

  • alt text In Add webhook page, you need to fill the following details

      Payload URL : http://jenkins-server-dns/github-webhook/
      Content type : application/json
      Secret : The secret that we created in Jenkins part
      Event : You can select the events which you need to trigger the webhook
    alt text

    Conclusion

    In this tutorial, we have learned how set up a GitHub webhook for Jenkins. If you have any issue regarding this tutorial, mention your issue in the comment section or reach me through my E-mail.

    Happy Coding