Jenkins
→ Manage Jenkins
→ Script Console
Input
:
import jenkins.model.*
// Pattern to search for. Regular expression.
def jobPattern = "*_PROD*"
// Should we be disabling or enabling jobs? "disable" or "enable", case-insensitive.
def disableOrEnable = "disable"
def lcFlag = disableOrEnable.toLowerCase()
if (lcFlag.equals("disable") || lcFlag.equals("enable")) {
def matchedJobs = Jenkins.instance.items.findAll { job ->
job.name =~ /$jobPattern/
}
matchedJobs.each { job ->
if (lcFlag.equals("disable")) {
println "Disabling matching job ${job.name}"
job.disable()
} else if (lcFlag.equals("enable")) {
println "Enabling matching job ${job.name}"
job.enable()
}
}
} else {
println "disableOrEnable parameter ${disableOrEnable} is not a valid option."
}
→ Run
Result
Disabling matching job PRODSuite10
Disabling matching job PRODSuite14