Operations 10 min read

Comprehensive Guide to Jenkins Multibranch Pipeline for Pull‑Request and Branch‑Based CI/CD

This guide explains how to set up and use Jenkins multibranch pipelines—covering automatic branch and pull‑request discovery, conditional Jenkinsfile logic, GitHub webhook configuration, and troubleshooting—to create a fully automated CI/CD workflow for any Git‑based project.

DevOps Cloud Academy
DevOps Cloud Academy
DevOps Cloud Academy
Comprehensive Guide to Jenkins Multibranch Pipeline for Pull‑Request and Branch‑Based CI/CD

This article introduces Jenkins multibranch pipelines as a Git‑based, pipeline‑as‑code solution for building automated CI/CD workflows that can trigger on both branch creation and pull‑request events.

A multibranch pipeline automatically discovers new branches or PRs in SCM (GitHub, Bitbucket, GitLab) and creates a dedicated pipeline for each, using the Jenkinsfile stored in the repository.

The guide shows how to add conditional logic in the Jenkinsfile—e.g., using when { branch 'develop' } to run deployment steps only on the develop branch while feature branches run only unit tests and static analysis.

It outlines a typical workflow: developers push code to a feature branch, open a PR, Jenkins runs unit tests and Sonar analysis, the PR status is reported back to GitHub, and after merging to develop or master the pipeline proceeds with build and deployment to the appropriate environment.

An example Jenkinsfile is provided: pipeline { agent { node { label 'master' } } options { buildDiscarder logRotator(daysToKeepStr: '16', numToKeepStr: '10') } stages { stage('Cleanup Workspace') { steps { cleanWs(); sh """echo \"Cleaned Up Workspace For Project\"""" } } stage('Code Checkout') { steps { checkout([$class: 'GitSCM', branches: [[name: '*/main']], userRemoteConfigs: [[url: 'https://github.com/spring-projects/spring-petclinic.git']]]) } } stage('Unit Testing') { steps { sh """echo \"Running Unit Tests\"""" } } stage('Code Analysis') { steps { sh """echo \"Running Code Analysis\"""" } } stage('Build Deploy Code') { when { branch 'develop' } steps { sh """echo \"Building Artifact\""""; sh """echo \"Deploying Code\"""" } } } }

The step‑by‑step Jenkins UI configuration includes creating a new multibranch pipeline project, selecting GitHub as the source, adding credentials, configuring branch discovery (including PR discovery), setting the script path, and enabling log rotation.

It also details how to configure a GitHub webhook (payload URL http:// /github-webhook/ ) to send push and PR events to Jenkins, with tips for verifying successful delivery.

Finally, the article covers testing the pipeline, interpreting build results in Blue Ocean, and troubleshooting common problems such as branch discovery failures and webhook delivery issues.

CI/CDAutomationDevOpsgitJenkinspull requestMultibranch Pipeline
DevOps Cloud Academy
Written by

DevOps Cloud Academy

Exploring industry DevOps practices and technical expertise.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.