I found my problem. As expected, it was a simple one. The constructor
for PreBuildCleanup requires two arguments; the list of patterns and a
boolean determining whether or not to apply the patterns to directories.
Somehow I must have been looking at an old version of the javadoc for
hudson.plugins.ws_cleanup, before the directories option was added.
Here's the working script, which I ran from the Groovy console in
Jenkins 1.466.2.
Eric
======================================
import hudson.tasks.*
import hudson.plugins.ws_cleanup.*
List<Pattern> lp = new ArrayList<Pattern>();
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 PreBuildCleanup(lp, false) );
item.save();
}
else {
println("$item.name already has pre-build cleanup enabled");
}
}
}
=========================================
On 3/4/2013 5:05 PM, Eric Pyle wrote:
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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.