Trigerring Multibranch Pipelines

In the previous post (multibranch basics) we have described the basics of creating and using a multibranch pipeline (well, building was manual for each branch, which is not too practical).
In this post, we will learn how to trigger builds for branches using github webhooks.

Plugins invalved

GitHub wbehook handling

  • When a github hook message arrives at Jenkins (this is a HTTP POST message), the github plugins checks that it knows what was the repository and branch it was sent from
  • Github then uses the git plugin to use SCM polling (once) the repository for changes. If changes are found - new build is triggered.

Configuring trigerring in Jenkins

  • Make sure you have your credentials configured as described in Multibranch Basics
  • Configure in Jenkins
    • Create/Open your Multibranch Pipeline project
    • Under Branch Sources:
      • Click Add source
      • Select GitHub
      • Add or select your GitHub credentials
      • Enter your repository URL
      • Under Behaviors:
        • Add Discover branches
        • Add Discover pull requests from origin
        • Add Discover tags
    • Under Build Configuration:
      • Mode: by Jenkinsfile
      • Script Path: Jenkinsfile
    • Under Scan Multibranch Pipeline Triggers:
      • Check Scan by webhook
      • Set a trigger token (optional but recommended)

Configure trigerring in github

  • In your GitHub repository:
    • Go to Settings > Webhooks
    • Click Add webhook
  • Configure webhook:
1Payload URL: https://your-jenkins-url/github-webhook/
2Content type: application/json
3Secret: [Optional but recommended for security]
4
5Under "Which events would you like to trigger this webhook?"
6Select: "Just the push event" or customize based on your needs

Let's run it

  • Run the smee.io client as explained here
  • configure webhook in your repository as explained here
  • change something, commit and push.
  • Look at the configuration in a branch Does it work?