Author: Jayant Mali
- What is a Multibranch project?
- Steps to create a Multibranch project in Jenkins
- What is a Webhook?
- Steps to implement a Webhook on a Multibranch project
What is a Multibranch Pipeline?
The Multibranch Pipeline project type enables you to implement different Jenkinsfiles for different branches of the same project. In a Multibranch Pipeline project, Jenkins automatically discovers, manages, and executes Pipelines for branches that contain a Jenkinsfile in source control.
Steps to create a Multibranch Pipeline project in Jenkins
Step 1: Log in to Jenkins, then add a new item, and select Multibranch Pipeline.
Note: Make sure you have installed the required plugins -> git integration plugin, GitHub integration plugin, Github branch source, maven Integration plugin, pipeline Maven Integration Plugin, Pipeline multi-branch, and build pipeline plugin.
Step 2: Add the display and description as required (optional).
Step 3: Add the SCM URL and id, password on credentials of SCM.
Step 4: For the behaviors, we have multiple options to filter the branch and for now we will keep it as default (Discover branch) so it automatically fetches the branch name.
Build Configuration: The mode is Jenkinsfile by default, which means only particular branches will be built with Jenkinsfile.
Step 5: For the scan of the Multibranch Pipeline we can use the “periodically if not otherwise run” option and set the interval based on the requirement. There are some other options called Webhook which we will see later.
Step 6: Click on Apply and then Save.
Step 7: Now try to make some changes in the repository. The changes you make will scan and the pipeline will automatically start triggering.
What is a Webhook?
Webhook is a mechanism to automatically trigger the build of a Jenkins project in response to a commit pushed to a Git repository.
Steps to implement a Webhook on a Multibranch project
Step 1: First we need to download the ngrok setup from https://ngrok.com/download.
Step 2: After successfully installing the setup, we need to paste the command in ngrok cmd.
Command -> ngrok http 8080
This will give a forwarding URL which will help in enabling Webhook.
Step 3: Now go to the repository and its settings -> Webhook.
Now for the payload URL, we are required to paste the code.
Here we can add the value of queryParams to any as per choice and then the same we need to mention in Jenkins.
Step 4: Click on Save Changes.
Step 5: Back to Jenkins and for the Webhook we need to add the plugin.
Go to Dashboard-> manage Jenkins -> manage Plugins -> Available and here search for: Multibranch Scan Webhook Trigger”.
Step 6: After installing the plugin, restart Jenkins so the latest installation will be visible.
The change we need to make in multi-branch projects is to disable periodically if not otherwise run and select for scan by Webhook.
Note: Give the token name the same as the payload URL of GitHub.
Step 7: Click on apply and then save.
Step 8: Try to make some changes in the repository so that a Webhook will trigger and the pipeline will start automatically.