Global "disable triggers" options

1,294 views
Skip to first unread message

Michael Giroux

unread,
Nov 7, 2016, 9:04:51 AM11/7/16
to Jenkins Users
We have a large jenkins configuration with 1700 jobs.  We have two use cases in which the configuration is copied. We make a copy of the configuration prior to any upgrade:

1. for purposes of testing new version and plugins prior to an upgrade
2. to have a running instance of the previous version to allow "emergency builds" for projects that will not build in new version after an upgrade.

In both of these use cases, we have two copies of Jenkins running at the same time (on different ports of course), the old version, and the new version.  In either case, we want to disable the build triggers for one of the instances.  We do not want two copies of jenkins building the same project based on polling, or due to upstream builds and/or snapshot changes.

We can use "prepare to shutdown" to suspend one instance.  But if we cancel shutdown to allow a specific build to be run, the flood gates open.

It would be helpful  if there was an option to allow manual builds even when "prepare to shutdown" is in effect.  Or, as the subject line suggests, an option to disable triggers. Such an option should have an initial state set by a system property allowing us to launch Jenkins with the option initially on or off.

Similar requests have been made previously:

I would be interested in hearing how other users handle this case, especially case #2 in which we wish to have the old instance of Jenkins available to run builds that might not execute in the new version.

Michael


Donald Morton

unread,
Nov 14, 2016, 6:18:02 PM11/14/16
to Jenkins Users
I've run a groovy script to disable all jobs before. Then, I just enable the jobs I want to run. The problem with that, though is that Pipeline jobs can't be disabled. So, I normally have to go into the test instance and manually remove the triggers on the Pipeline jobs to keep them from running. I'm sure a script could do this, too, but I haven't seen one.

Ted Xiao

unread,
Nov 15, 2016, 8:56:58 AM11/15/16
to Jenkins Users
We run groovy script to remove timer trigger or other triggers, sample code
import hudson.model.*
import hudson.triggers.*
import jenkins.model.*
import com.cloudbees.hudson.plugins.folder.Folder

def TIMER_TRIGGER_DESCRIPTOR = Hudson.instance.getDescriptorOrDie(TimerTrigger.class)

def removeTrigger
removeTrigger={ it ->
    if (it==null || it?.name=='the preserved job'){
      return
    }
    if(it instanceof Folder){
      for(subitem in it.items){
        removeTrigger(subitem)
      }
      return
    }

    def timertrigger = it.getTriggers().get(TIMER_TRIGGER_DESCRIPTOR)
    if(timertrigger != null){  println("remove Trigger for "+  it.url);
        it.removeTrigger(TIMER_TRIGGER_DESCRIPTOR)
    }
}

def name=build.buildVariables.name.replace('/job/','')
println "will remove timer from ${name}"
removeTrigger(Jenkins.instance.getItem(name,(ItemGroup)null))



Reply all
Reply to author
Forward
0 new messages