Вот скрипт, который я сделал, который обнаруживает многоотраслевые или организационные триггеры. Если у проекта его еще нет, он создаст триггер. Примечание. Часть addTrigger закомментирована, поэтому ее можно безопасно запускать как есть.
import com.cloudbees.hudson.plugins.folder.computed.PeriodicFolderTrigger
import jenkins.model.Jenkins
import jenkins.branch.OrganizationFolder
import hudson.model.Job
projects = [:]
Jenkins.instance.getAllItems(AbstractItem.class).each { j ->
String jc = j.class.simpleName
if(!(jc in projects)) {
projects[jc] = 0
}
projects[jc]++
}
println "Count projects by type for: " + Jenkins.getInstance().getRootUrl()
println " Current Jenkins version: " + Jenkins.getInstance().version
projects.each { type, count ->
println " ${type}: ${count}"
}
println "\n-------Organization Items-------"
Jenkins.instance.getAllItems(jenkins.branch.OrganizationFolder.class).each { j ->
String jobName = j.fullName
Integer triggerCount = j.triggers.findAll { k,v -> v instanceof com.cloudbees.hudson.plugins.folder.computed.PeriodicFolderTrigger}.size()
if (triggerCount > 0) {
myInterval = j.triggers.findAll { k,v -> v instanceof com.cloudbees.hudson.plugins.folder.computed.PeriodicFolderTrigger}
.each { k,v -> println " trigger count: ${triggerCount} Interval: ${v.getInterval()}, jobName: ${jobName}" }
}
else {
def newInterval = new PeriodicFolderTrigger("1d")
println " trigger count: ${triggerCount} Interval: NULL, jobName: ${jobName}"
//println " creating trigger for ${jobName}"
//j.addTrigger(newInterval)
//j.save()
}
}
println "\n-------Multibranch Items-------"
Jenkins.instance.getAllItems(org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject.class).each { j ->
String jobName = j.fullName
Integer triggerCount = j.triggers.findAll { k,v -> v instanceof com.cloudbees.hudson.plugins.folder.computed.PeriodicFolderTrigger}.size()
if (triggerCount > 0) {
myInterval = j.triggers.findAll { k,v -> v instanceof com.cloudbees.hudson.plugins.folder.computed.PeriodicFolderTrigger}
.each { k,v -> println " trigger count: ${triggerCount} Interval: ${v.getInterval()}, jobName: ${jobName}" }
}
else {
def newInterval = new PeriodicFolderTrigger("1d")
println " trigger count: ${triggerCount} Interval: NULL, jobName: ${jobName}"
//println " creating trigger for ${jobName}"
//j.addTrigger(newInterval)
//j.save()
}
}
return