Operations 11 min read

Step‑by‑Step Guide to Setting Up a Jenkins Multibranch Pipeline for CI/CD

This tutorial explains how to create, configure, and troubleshoot a Jenkins multibranch pipeline that automatically builds, tests, and deploys code based on Git branches and pull‑request events, including a complete Jenkinsfile example and webhook setup for seamless CI/CD integration.

DevOps Cloud Academy
DevOps Cloud Academy
DevOps Cloud Academy
Step‑by‑Step Guide to Setting Up a Jenkins Multibranch Pipeline for CI/CD

This article introduces Jenkins multibranch pipelines as a Git‑based, pipeline‑as‑code solution for automating CI/CD workflows, highlighting why they are essential for modern development teams.

It explains the core concepts: Jenkins automatically discovers new branches in a SCM repository (GitHub, Bitbucket, or GitLab), creates a pipeline for each branch, and runs the stages defined in a Jenkinsfile . Pull‑request (PR) discovery can be enabled so that pipelines are triggered only when a PR is opened.

The guide then presents a practical Jenkinsfile example that includes stages for workspace cleanup, code checkout, unit testing, static code analysis, conditional building and deployment (only on the develop branch), and demonstrates how to add conditional logic with the when directive.

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\"""" } }
    }
}

Next, the article walks through the Jenkins UI configuration: creating a new multibranch pipeline project, selecting the SCM source, adding credentials, choosing branch discovery strategies (all branches or PR‑only), optionally renaming the Jenkinsfile path, and enabling log rotation.

It then details how to configure a GitHub webhook so that push and PR events are sent to Jenkins ( /github-webhook/ endpoint), including steps to verify the webhook status and troubleshoot failures.

After the setup, the guide shows how to test the pipeline by creating feature branches, opening PRs, and observing automatic builds, unit tests, Sonar analysis, and conditional deployment. Screenshots illustrate the Blue Ocean view of successful and skipped stages.

Finally, common troubleshooting tips are provided for branch discovery issues and webhook failures, advising users to trigger an immediate repository scan, check Jenkins system logs, and examine webhook delivery payloads.

CI/CDAutomationDevOpsgitJenkinsMultibranch 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.