I'm finally trying to get this implemented. I'm using some of the example at
http://stackoverflow.com/a/23226035/2658793 to execute a script on each node, and getting a NullPointerException. I was curious if your experience with the 'do some cleanup' step you mentioned has ever included running a script on each node?
Any ideas would be much appreciated. I'd much prefer this model to having maintenance jobs for every single node, filling up the build queues.
import hudson.util.*
Jenkins jenkins = Jenkins.instance
for (Node slave in jenkins.nodes) {
def output = new java.io.ByteArrayOutputStream();
def listener = new hudson.util.StreamTaskListener(output);
def launcher = slave.createLauncher(listener);
def command = new hudson.util.ArgumentListBuilder();
command.addTokenized("ipconfig");
def ps = new hudson.Launcher.ProcStarter();
ps = ps.cmds(command);
def proc = launcher.launch(ps);
def retcode = proc.join();
println("ret code="+retcode)
}
Processing Slave vmbuild10
java.lang.NullPointerException
at hudson.model.Slave.createLauncher(Slave.java:362)
at hudson.model.Slave$createLauncher.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
at Script1.run(Script1.groovy:14)
...