Jenkins multibranch pipeline Scan without execution

前端 未结 4 2060
不思量自难忘°
不思量自难忘° 2021-02-06 22:04

Is it possible to Scan a Multibranch Pipeline to detect the branches with a Jenkinsfile, but without the pipeline execution?

My projects have different branc

相关标签:
4条回答
  • 2021-02-06 22:13

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

    This prevents Jenkins from building everything with an Jenkinsfile.

    0 讨论(0)
  • 2021-02-06 22:23

    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()
                ...
              }
            }
          }
        }
      }
      ...
    }
    
    0 讨论(0)
  • 2021-02-06 22:23

    If you are using job-dsl you could simply do this and it will scan everything without actually running the build the first time you index.

    organizationFolder('Some folder name') {
      buildStrategies {
        skipInitialBuildOnFirstBranchIndexing()
      }
    }
    
    0 讨论(0)
  • 2021-02-06 22:39

    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.

    0 讨论(0)
提交回复
热议问题