Wesley Hartford created JENKINS-12785:
-----------------------------------------

             Summary: Groovy script console SCMTrigger example causes invalid 
configurationw
                 Key: JENKINS-12785
                 URL: https://issues.jenkins-ci.org/browse/JENKINS-12785
             Project: Jenkins
          Issue Type: Bug
          Components: other
            Reporter: Wesley Hartford


The wiki page at 
[https://wiki.jenkins-ci.org/display/JENKINS/Change+SCMTrigger+for+each+project+to+disable+during+the+night+and+the+week-end]
 has an sample script which modifies the SCM trigger schedule. The script does 
not set the _job_ field of the newly created trigger. I recently used a 
modified version of this script and encountered many NullPointerExceptions. I 
would recommend changing the sample to the following:

{code:java}
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())
    newTrigger.job = item

    item.removeTrigger(SCM_TRIGGER_DESCRIPTOR)
    item.addTrigger(newTrigger)
  }
  else
  {
    println "> Nothing to do"
  }
}
{code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.jenkins-ci.org/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to