---Begin Script---
import hudson.model.*
import hudson.triggers.*
TriggerDescriptor TIMER_TRIGGER_DESCRIPTOR = Hudson.instance.getDescriptorOrDie(TimerTrigger.class)
assert TIMER_TRIGGER_DESCRIPTOR != null;
view = Hudson.instance.getView("Trunk Jobs")
for(item in view.getItems()) {
println(item.name)
AbstractProject project = (AbstractProject) item;
newSpecString = new String("0 2 * * 1-5")
def trigger = item.getTriggers().get(TIMER_TRIGGER_DESCRIPTOR)
if(trigger != null && trigger instanceof TimerTrigger) {
println("> Removing existing Timer Trigger => $trigger.spec")
project.removeTrigger(TIMER_TRIGGER_DESCRIPTOR)
}
def newTrigger = new TimerTrigger(newSpecString)
println("> Adding new Timer Trigger => $newTrigger.spec")
project.addTrigger(newTrigger)
}
---End Script---
The log showed the following error for all the jobs modified:
---Begin Error---
Mar 7, 2011 2:01:03 AM hudson.triggers.Trigger checkTriggers
WARNING: hudson.triggers.TimerTrigger.run() failed for affiliate-cookier
java.lang.NullPointerException
at hudson.triggers.TimerTrigger.run(TimerTrigger.java:53)
at hudson.triggers.Trigger.checkTriggers(Trigger.java:249)
at hudson.triggers.Trigger$Cron.doRun(Trigger.java:197)
at hudson.triggers.SafeTimerTask.run(SafeTimerTask.java:54)
at java.util.TimerThread.mainLoop(Timer.java:512)
at java.util.TimerThread.run(Timer.java:462)
---End Error---
Did I miss something in the groovy script? Should the configurations be reloaded after a change like this?
Jason Schadel
AWeber Communications, Inc.
http://www.aweber.com
Old post, I know, but I just came across this issue so thought I'd add my findings. https://issues.jenkins-ci.org/browse/JENKINS-14771 looks to be the same issue, the reason for the NPE is that while you've added the trigger to the job you haven't told the trigger about the job. To work around it I used this code:
--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/8e179ac5-a7ea-44ae-b0b8-3fef0fda9ec6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.