I've a script to find the all idle slaves and create a text file using Jenkins system groovy. I'm able to create a empty file and find all idle slaves where as coming to append to the file "idle_slaves.list" i got java.io.FileNotFoundException exception. Can somebody help me on this?
import jenkins.*
import hudson.*
import jenkins.model.Jenkins
jenkins = jenkins.model.Jenkins
File file1 = new File(build.workspace.toString() + "/idle_slaves.list")
if(build.workspace.isRemote())
{
channel = build.workspace.channel;
fp = new FilePath(channel, build.workspace.toString() + "/idle_slaves.list")
} else {
fp = new FilePath(new File(build.workspace.toString() + "/idle_slaves.list"))
}
if(fp != null)
{
fp.write("", null); //writing to file
}
for (node in Jenkins.instance.nodes) {
computer = node.toComputer()
if (computer.getChannel() == null) {
continue
}
if (computer.isIdle()) {
slave = node.name.toString()
file1.append( slave )
}
}
Jenkins 2.46
groovy 2.0