Is it possible to Scan a Multibranch Pipeline to detect the branches with a Jenkinsfile
, but without the pipeline execution?
My projects have different branches and I don't want that all the children pipelines branches with a Jenkinsfile to start to execute when I launch a build scan from the parent pipeline multibranch.
The Multibranch Pipeline project type enables you to implement different Jenkinsfiles for different branches of the same project. In a Multibranch Pipeline project, Jenkins automatically discovers, manages and executes Pipelines for branches which contain a Jenkinsfile in source control.
Jenkins Pipeline Vs. Multibranch Pipeline. A multibranch pipeline is meant for building multiple branches from a repository and deploy to multiple environments if required. A pipeline job supports both pipeline steps to be added in Jenkins configuration and form SCM.
Head over to your Jenkins instance and create a new item. Enter a name for the job, and select the “Multibranch Pipeline” option at the end of the screen. Then, click on the OK button. In the next screen, go to the “Branch sources” tab, click on the “Add source” button, and choose “Git” from the dropdown menu.
In your Branch Sources section you can add a Property named Suppress automatic SCM triggering.
This prevents Jenkins from building everything with an Jenkinsfile
.
Also, you can do it programatically
import jenkins.branch.* import jenkins.model.Jenkins for (f in Jenkins.instance.getAllItems(jenkins.branch.MultiBranchProject.class)) { if (f.parent instanceof jenkins.branch.OrganizationFolder) { continue; } for (s in f.sources) { def prop = new jenkins.branch.NoTriggerBranchProperty(); def propList = [prop] as jenkins.branch.BranchProperty[]; def strategy = new jenkins.branch.DefaultBranchPropertyStrategy(propList); s.setStrategy(strategy); } f.computation.run() }
This is a Groovy snippet you can execute in Jenkins, it's gonna do the scanning but will not start new "builds" for all discovered branches.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With