Parallel jobs using build flow plugin with loop in jenkins
parallel
takes a list of Closures, so you should be able to use collect
to return a list:
import jenkins.model.Jenkinsimport java.util.regex.*Pattern myRegex = ~/release_status.*/parallel jenkins.model.Jenkins.instance.items.collect { item -> { -> if (item.name ==~ myRegex) { build( "$item.name" ) } }}
An alternative that only returns a Closure if the name passes (rather than a Closure for every item, a lot of which will finish early) is:
import jenkins.model.Jenkinsimport java.util.regex.*Pattern myRegex = ~/release_status.*/parallel Jenkins.instance.items.findAll { item -> item.name ==~ myRegex} .collect { item -> { -> build("$item.name") } }
Here is my solution that might be helpful with Folders plugin:
import jenkins.model.Jenkins//Configuration blockdef dryRun = truedef projectFolder = 'Path/To/Folder'def phases = ['.*-Build','.*-Deploy', '.*-Regression', '.*Service-Full-Performance-Test']//Configuration blockdef phasesRegex = []phases.each{ phasesRegex.push(~/${projectFolder}\/${it}/)}def jobs = []items = jenkins.model.Jenkins.instance.getItemByFullName(projectFolder);items.getAllJobs().collect{ jobs.push(it.getFullName())}phasesRegex.each{ run = jobs.grep(it) parallel run.collect{ job -> { -> if (dryRun) println "Dry Run of Job: ${job}" else build(job) } }}