jobs modified via script console do not take effect

14 views
Skip to first unread message

Arturo Flores

unread,
Oct 24, 2017, 7:06:14 PM10/24/17
to Jenkins Users
I used a script similar to this one to modify a job via the script console (http://[my_jenkins_url]/script ):

import hudson.triggers.*

midnightTrigger = new TimerTrigger("* * * * *")

job = Jenkins.instance.getItem("some jenkins job")
job.addTrigger( midnightTrigger )

for( trigger in vortexJob.triggers.values() ) {
  println( trigger )
  println( trigger.spec )
}

job.save()


For the sake of this example, I set it to run every minute.  The output is as expected:
hudson.triggers.TimerTrigger@7890613d
* * * * *

However, the job does not run every minute.  If I view the job via the web interface, I see that the job is scheduled to run every minute, but it simply does not run.  If I save using the web interface, then the job does run every minute.

Any idea why?

Reinhold Fuereder

unread,
Oct 25, 2017, 1:52:21 AM10/25/17
to jenkins...@googlegroups.com

Hi Arturo,

 

maybe this answer by Andrew on Saturday, 23 September 2017 03:01:26 UTC+5:30 explains it:

Yeah, the job has to run at least once after you've added the triggers directive for it to register, and then it'll be fine.

 

Please see https://groups.google.com/forum/?utm_medium=email&utm_source=footer#!msg/jenkinsci-users/wI0lzVSjmFg/dUPberPmAQAJ for more details...

 

HTH Reinhold

Arturo Flores

unread,
Oct 25, 2017, 1:53:59 PM10/25/17
to Jenkins Users
It doesn't seem that was the answer.

So I modified the script by adding:

job.scheduleBuild(0)

at the end to trigger a build.  I observed the job build in the web interface.  However, the job did not build every minute after this.  I also triggered a build by clicking the "Build Now" link in the web interface.  Even after this, the job does not build every minute as scheduled.  However, if I click save on the web interface at http://[my jenkins url/[some jenkins job]/configure , then the job starts building every minute.  I did not make any changes in the web interface job configuration page, I simply pulled up the page and clicked save.

Does this sound like a bug?  I have several dozen jobs for which I want to change the build triggers.  I am hoping to be able to do this via the script console and not have to do it manually.
Reply all
Reply to author
Forward
0 new messages