I've been working on a Groovy script to add PreBuildCleanup to certain jobs. I followed the example of the Groovy script to add timestamper to all jobs [1]. The problem is, I can't come up with the right constructor for the PreBuildCleanup. I know it must be simple, but I'm just learning to poke around in the Jenkins classes. Here's what I try, running from the Script Console.

Thanks,
Eric

[1] https://wiki.jenkins-ci.org/display/JENKINS/Enable+Timestamper+plugin+on+all+jobs

import hudson.model.*
import hudson.maven.*
import hudson.tasks.*

for(item in Hudson.instance.items) {
  if (item.name == "my_example_jenkins_job") {
    hasPreClean = false;
    item.buildWrappers.values().each{
      if (it instanceof hudson.plugins.ws_cleanup.PreBuildCleanup){
        hasPreClean = true;
      }
    }

    if(!hasPreClean)
    {
      println(">>>>>>>> Adding PreClean to $item.name")
item.getBuildWrappersList().add(new hudson.plugins.ws_cleanup.PreBuildCleanup() );
      item.save()

    }
  }
}

And the output:

Adding PreClean to my_example_jenkins_job
groovy.lang.GroovyRuntimeException: Could not find matching constructor for: 
hudson.plugins.ws_cleanup.PreBuildCleanup()
        at groovy.lang.MetaClassImpl.invokeConstructor(MetaClassImpl.java:1466)
        at groovy.lang.MetaClassImpl.invokeConstructor(MetaClassImpl.java:1382)
        at 
org.codehaus.groovy.runtime.callsite.MetaClassConstructorSite.callConstructor(MetaClassConstructorSite.java:46)
        at 
org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:54)
        at 
org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:182)
        at 
org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:186)
        at Script1.run(Script1.groovy:19)
        at groovy.lang.GroovyShell.evaluate(GroovyShell.java:580)
        at groovy.lang.GroovyShell.evaluate(GroovyShell.java:618)
        at groovy.lang.GroovyShell.evaluate(GroovyShell.java:589)
        at 
hudson.util.RemotingDiagnostics$Script.call(RemotingDiagnostics.java:150)



--
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-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to