Jenkins multibranch pipeline Scan without execution

六月ゝ 毕业季﹏ 提交于 2019-12-04 09:57:21

问题


I´m starting to create my pipeline multibranch environment but i have founded a problem.

Can I run a build scan only to detect the branches with a Jenkinsfile but without the pipeline execution?

My projects have different branches and i dont want when i launch a build scan from the parent pipeline multibranch all the children pipelines foreach branches with a Jenkinsfile starts to execute.

Thanks by the help!


回答1:


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

This prevents Jenkins from building everything with an Jenkinsfile.




回答2:


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.




回答3:


To add to @Stqs's answer, you could also set noTriggerBranchProperty it using Job DSL plugin, e.g.:

multibranchPipelineJob('example') {
  ...
  branchSources {
    branchSource {
      ...
      strategy {
        defaultBranchPropertyStrategy {
          props {
            // Suppresses the normal SCM commit trigger coming from branch indexing
            noTriggerBranchProperty()
            ...
          }
        }
      }
    }
  }
  ...
}


来源:https://stackoverflow.com/questions/44004636/jenkins-multibranch-pipeline-scan-without-execution

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!