Skip to content

Commit 3bcc733

Browse files
author
Kirill Gostaf
committed
Script to disable Build periodically trigger
1 parent 6491b79 commit 3bcc733

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
The script was created on 2019-07-21
3+
by Kirill Gostaf, kgostaf@cloudbees.com
4+
5+
This script will iterate over all the projects, and check whether a job has Build periodically trigger enabled.
6+
If the project type is Freestyle job the Build periodically trigger will be disabled.
7+
Otherwise, it prints the name of the project without modifying the trigger settings.
8+
For a pipeline project, i.e. org.jenkinsci.plugins.workflow.job.WorkflowJob, you may want to modify
9+
the Jenkins file that contains `triggers { cron(H/4 * * * *) }` instructions.
10+
*/
11+
12+
13+
import hudson.model.*
14+
import hudson.triggers.*
15+
TriggerDescriptor TIMER_TRIGGER_DESCRIPTOR = Hudson.instance.getDescriptorOrDie(TimerTrigger.class)
16+
17+
for(item in Jenkins.instance.getAllItems(Job))
18+
{
19+
def timertrigger = item.getTriggers().get(TIMER_TRIGGER_DESCRIPTOR)
20+
if (timertrigger) {
21+
if (item.class.canonicalName == "hudson.model.FreeStyleProject") {
22+
item.removeTrigger(TIMER_TRIGGER_DESCRIPTOR)
23+
println(item.name + " Build periodically trigger disabled successfully");
24+
}
25+
else {
26+
println(item.name + " not a Freestyle project. Build periodically trigger is still enabled");
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)