How to Build a Multibranch Pipeline in Jenkins
A Multibranch Pipeline scans the repo and creates a job for every branch that contains a Jenkinsfile.
Point a Multibranch Pipeline at your repo; Jenkins discovers branches and PRs, runs their Jenkinsfile, and removes jobs when branches are deleted.
Branch-aware Jenkinsfile
The same Jenkinsfile runs per branch; use env.BRANCH_NAME to vary behavior such as deploying only from main.
Jenkinsfile
pipeline {
agent any
stages {
stage('Build') {
steps { sh 'make build' }
}
stage('Deploy') {
when { branch 'main' }
steps { sh './deploy.sh' }
}
}
}Notes
- Configure branch sources and discovery (branches, PRs from origin/fork) in the Multibranch Pipeline job config.
- env.BRANCH_NAME and the when { branch } condition let one Jenkinsfile behave differently per branch.
- Orphaned branch jobs are pruned automatically on the next scan.
Related guides
How to Use a Jenkinsfile with a Shared LibraryReuse pipeline code across Jenkins repos with a shared library, loading it via @Library and calling custom st…
How to Run Stages in Parallel in a Jenkins PipelineRun independent Jenkins pipeline stages at the same time with a parallel block, so lint, unit, and integratio…