Created
April 10, 2018 14:54
-
-
Save jakub-bochenski/e152affa4719b0794a3311fcc7abe590 to your computer and use it in GitHub Desktop.
Find all projects building a SCM repository
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject | |
import org.jenkinsci.plugins.workflow.job.WorkflowJob | |
import hudson.model.AbstractProject | |
import jenkins.*; | |
import jenkins.model.*; | |
import hudson.*; | |
import hudson.model.*; | |
String query = build.envVars['QUERY'] | |
def workflowFilter = { it.pollingBaselines?.keys()?.any{ it.contains query } } | |
Map scmFilters = [ | |
'hudson.scm.NullSCM' : { false }, | |
'hudson.scm.SubversionSCM' : { it.locations.any{ it.remote.contains query } }, | |
'hudson.plugins.git.GitSCM' : { it.userRemoteConfigs.any{ it.url.contains query } } | |
] | |
def print = { println it.displayName + ' [' + it.pronoun + '] ' + it.absoluteUrl } | |
Jenkins.instance.allItems | |
.findAll{it instanceof AbstractProject} | |
.findAll{ scmFilters[it.scm.class.name]?.call(it.scm) } | |
.each print | |
Jenkins.instance.allItems | |
.findAll{it instanceof WorkflowMultiBranchProject} | |
.findAll{ it.items?.any(workflowFilter) } | |
.each print | |
Jenkins.instance.allItems | |
.findAll{it instanceof WorkflowJob} | |
.findAll{!(it.parent instanceof WorkflowMultiBranchProject)} | |
.findAll(workflowFilter) | |
.each print |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment