Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Jenkins script to bring slave online. The job would wait for 10 mins if the slave doesnt come online within that time it ll fail.
import hudson.model.*
import hudson.AbortException;
def resolver = build.buildVariableResolver
// def node_names = resolver.resolve("NODE_LIST").split(",")
timeout_seconds = 600 // 10 mins
sleepTime=30 // seconds
def node_name=resolver.resolve("NODE_NAME").replaceAll("\\s","")
slave = Hudson.instance.slaves.find({it.name == node_name});
if (slave != null) {
computer = slave.getComputer();
if (computer.isOffline()) {
println "$node_name is offline.";
computer.connect(true)
long startTime = System.currentTimeMillis(); //fetch starting time
while(computer.isOffline()||(System.currentTimeMillis()-startTime)<timeout_seconds*1000){
println "$node_name still offline.";
println "Sleep for $sleepTime seconds"
sleep(sleepTime*1000)
}
if (computer.isOffline()) {
throw new Exception('$node_name didnt come online. Kindly check')
}
}else {
println "OK: $node_name is online";
}
} else {
println "Slave $node_name not found!";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.