Problem Statement
What is a Multibranch Pipeline in Jenkins?
Explanation
Multibranch Pipeline automatically discovers branches and pull requests in SCM repository, creating pipeline instances for each with Jenkinsfile. When a new branch is created, Jenkins detects it and creates corresponding pipeline. When branch is deleted, the pipeline is removed. This eliminates manual job creation for each branch and ensures all branches use the same pipeline definition.
Configuration: create Multibranch Pipeline item, specify repository URL and credentials, configure branch discovery (which branches to build), optionally filter branches with regex or wildcards, set scan interval for detecting new branches. Jenkins scans repository periodically or on webhook, finding Jenkinsfiles and creating/updating pipelines accordingly.
Benefits include automatic branch discovery (no manual job creation), consistent pipeline across branches (all use same Jenkinsfile), pull request building (test changes before merge), branch-specific behavior (when directive for branch-specific logic), automatic cleanup (orphaned pipelines removed). Example branch-specific logic:
```groovy
stage('Deploy') {
when { branch 'main' }
steps { sh './deploy-prod.sh' }
}
```
Pull request support: Multibranch Pipeline can build pull requests, reporting status back to SCM (GitHub, GitLab, Bitbucket). PR builds test changes in isolation before merging. Configure PR discovery in Multibranch settings. Understanding Multibranch Pipelines is essential for modern Git workflows with feature branches and pull requests.
