Update jobs via Script Console does not take effect

38 views
Skip to first unread message

Sverre Moe

unread,
Sep 21, 2015, 10:11:40 AM9/21/15
to Jenkins Users
It seems when I updated a Job configuration with Groovy in the Script console it didn't really take effect.

def jenkinsInstance = jenkins.model.Jenkins.getInstance()
def developmentView = jenkinsInstance.getView("Development")
developmentView.getItems().each { project ->
    def trigger = new hudson.triggers.SCMTrigger("H/5 * * * *")
    project.addTrigger(trigger)
    project.save()
}

I later checked one of my project and found it hadn't checked Git for any changes for some time. In fact it was well over 5 minutes since last check. I triggered a build manually and it found new changes. I went into Configuration of that project, checked the settings and they where good SCM trigger was set to 5 minutes. I then saved the project configuration (even though I didn't change anything). After I did that I later checked the SCM log and it did from that moment forward check Git every 5 minutes for changes.

So it looked like the Groovy script I executed didn't take effect, even though it actually did update the configuration properly.

Am I missing an extra step after project.save()?

Daniel Beck

unread,
Sep 21, 2015, 12:21:14 PM9/21/15
to jenkins...@googlegroups.com
You forgot to `start(Job, boolean)` the trigger you added. You'll probably also need to `stop()` any existing SCMTrigger that gets replaced by yours.
> --
> 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-use...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/ea96dd9a-4b48-4fcf-a6b9-0f4d0dc163e4%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Sverre Moe

unread,
Sep 25, 2015, 8:44:31 AM9/25/15
to Jenkins Users, m...@beckweb.net
I have added stopping the old trigger and starting the new trigger. 

I have also a solution that worked without this:
def jenkinsInstance = jenkins.model.Jenkins.getInstance()
def SCM_TRIGGER_DESCRIPTOR = jenkinsInstance.getDescriptorOrDie(SCMTrigger.class)


def developmentView = jenkinsInstance.getView("
Development")
developmentView.getItems().each { project ->
  project.removeTrigger(SCM_TRIGGER_DESCRIPTOR)

    def trigger = new hudson.triggers.SCMTrigger("H/5 * * * *")
  trigger.job = project
    project.addTrigger(trigger)
    project.save()
}
Reply all
Reply to author
Forward
0 new messages