====== Jenkins: Multibranch Pipeline ====== **General Information** A Jenkins Multibranch pipeline job is flexible because it scans your project for all available branches that have a matching Jenkinsfile and adds that pipeline job. **Checklist** * Jenkins master server installed * Available Git repo ---- ====== Creating a multibranch pipeline ====== Creating a multibranch pipeline is similar to creating a standard pipeline job. * Click "New Item" * Enter an item name: * Click "Multibranch Pipeline", then click "Ok" ---- ===== Initial Configuration ===== After creation, you are brought to the initial multibranch pipeline configuration page. * Under "Branch Sources", click "Add source", then click the type of project (such as Git) * Project Repository: * Credentials: Select your saved project credentials (if required) * Behaviors: Default is to discover all branches * Build strategies: There are a number of build strategies that can influence which branches are built and when. * See the next section for some of them. * **Note**: The default of no build strategies will execute each pipeline found in each branch upon initial discovery (such as when you click Save) OR after each scan that finds a commit change. If this is NOT the desired behavior, look at the available build strategies. * Build Configuration * Mode: by Jenkinsfile * Script Path: Enter the path to the Jenkinsfile stored in the project. This is the pipeline file that will be scanned for in each branch. * Scan Multibranch Pipeline Triggers: Check this box and select how often to scan the project for branches and Jenkinsfiles in those branches. * Click "Save" to save the job configuration ---- ===== Build Strategies ===== Build strategies are ways to limit what branches are built and when. * "Suppress automatic SCM triggering" * Do not build on changes during a multibranch scan. * **Note**: This strategy is removed when you install the plugin "Basic Branch Build Strategies Plugin" below, but can be achieved in a different way. * Install the plugin: [[https://wiki.jenkins.io/display/JENKINS/Basic+Branch+Build+Strategies+Plugin|Basic Branch Build Strategies Plugin]] * "All Strategies Match" * The strategies contained are all used together. This strategy must be used to contain the next two if you don't want automatic scm triggering. * "Skip initial build on first branch indexing" * Don't build upon initial branch discovery (will build every time after if changes are discovered unless further build strategies are added) * "Named Branches" * Add "Wildcard include/exclude" * "Exclude: *" * This will exclude all matched branch names from building - useful if you only want to build branches explicitly and not automatically. (such as deploy jobs) You could also only exclude branches that may deploy to production (For example: master) ----