Skip to main content

Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Change SCMTrigger for each project to disable during the night and the weekend

This script lets you easily change all jobs running every minutes so that it gets disabled between 21:00 and 07:00 and on Saturday and Sunday.

import hudson.model.*
import hudson.triggers.*


TriggerDescriptor SCM_TRIGGER_DESCRIPTOR = Hudson.instance.getDescriptorOrDie(SCMTrigger.class)
assert SCM_TRIGGER_DESCRIPTOR != null;

for(item in Hudson.instance.items)
{
    println("Working on project <$item.name>")
		
		def trigger = item.getTriggers().get(SCM_TRIGGER_DESCRIPTOR)
		if(trigger != null && trigger instanceof SCMTrigger)
		{
      print("> $trigger.spec")
  		String[] parts = trigger.spec.split(" ");
  		
      //Do wanted modifs
      if(parts[1] == "*" )
  		{
  			parts[1] = "7-21"
  		}
  		if(parts[4] == "*")
  		{
  			parts[4] = "1-5"
  		}
  		//end modifs
  
  		StringBuilder newSpec = new StringBuilder();
  		for(p in parts)
  		{
  			newSpec.append(p+" ");
  		}
  
  		println(" => $newSpec");
  
  		def newTrigger = new SCMTrigger(newSpec.toString())
  
   		AbstractProject project = (AbstractProject) item;
  
  		project.removeTrigger(SCM_TRIGGER_DESCRIPTOR)
      project.addTrigger(newTrigger)
  }
  else
  {
    println "> Nothing to do"
  }
}

Back to the top