Jenkins: Bulk editing jobs to remove a trigger
Posted by Admin • Thursday, December 17. 2015 • Category: DevOps, Java, Linux
I have about 200 jobs that have the HudsonStartupTrigger (this is a plugin) turned on. This makes all of them run every time the master is restarted, causing the build queue to go crazy. I don't know why people turned this on in so many jobs (probably blindly copying jobs) over the years, but I'd like it gone. I don't want to restart the master or uninstall the plugin.
Here is a script console snippet to do this (can be adapted to remove other triggers easily). This does not do folders, if you're using that plugin.
import hudson.triggers.*
for (item in Hudson.instance.items) {
name = item.name
if (item instanceof AbstractProject) {
triggers = ((AbstractProject)item).getTriggers()
triggers.each{descriptor, trigger ->
if (descriptor instanceof org.jvnet.hudson.plugins.triggers.startup.HudsonStartupTrigger$HudsonStartupDescriptor) {
out.println("Removing startup trigger from job " + name)
((AbstractProject)item).removeTrigger(descriptor)
}
}
}
}
Here is a script console snippet to do this (can be adapted to remove other triggers easily). This does not do folders, if you're using that plugin.
import hudson.triggers.*
for (item in Hudson.instance.items) {
name = item.name
if (item instanceof AbstractProject) {
triggers = ((AbstractProject)item).getTriggers()
triggers.each{descriptor, trigger ->
if (descriptor instanceof org.jvnet.hudson.plugins.triggers.startup.HudsonStartupTrigger$HudsonStartupDescriptor) {
out.println("Removing startup trigger from job " + name)
((AbstractProject)item).removeTrigger(descriptor)
}
}
}
}
0 Comments
Add Comment