Created
May 23, 2020 10:51
-
-
Save vishalTrivedi88/5a7fca5e39ef16c59d8c87e748ca3a31 to your computer and use it in GitHub Desktop.
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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