Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins multibranch pipeline Scan without execution

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.

like image 512
Daniel Majano Avatar asked May 16 '17 14:05

Daniel Majano


People also ask

What does scan Multibranch pipeline do?

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.

What is difference between pipeline and Multibranch pipeline?

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.

How does Jenkins use Multibranch pipeline?

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.


2 Answers

In your Branch Sources section you can add a Property named Suppress automatic SCM triggering.

This prevents Jenkins from building everything with an Jenkinsfile.

like image 180
42tg Avatar answered Oct 11 '22 09:10

42tg


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.

like image 30
Stqs Avatar answered Oct 11 '22 09:10

Stqs