I use jenkins master-slave configuration for capturing Performance metrics of a product. We have observed that jenkins-slave tends to accumulate memory and thus influences the P
Create a job e.g. "Reboot-Slave", and set it with shell "shutdown -r -t 0", and take the target slave name as a parameter. (in this way, the restart command will be executed directly on the target slave that you want to restart.)
Create another job e.g. "Reboot-Check-Slave-Online", in this job, you should call the 1st job and pass the target slave name as parameter, plus, you'd better write some logic to determine whether your slave finished the restarting and connected to Jenkins server again, you can implement it by adding an "Execute system groovy script" step in your job and write below code:
import hudson.model.*
def target_slave_param = "target_slave"
def resolver = build.buildVariableResolver
def target_slave = resolver.resolve(target_slave_param)
println "target_slave is: ${target_slave}"
def status = 0;
//do{
println "Searching for ${target_slave}";
slave = Hudson.instance.slaves.find({it.name == target_slave});
if (slave != null)
{
computer = slave.getComputer();
if (computer.isOffline())
{
println "Error! $target_slave is offline.";
status = 1;
}
else
{
println "OK: $target_slave is online";
}
}
else
{
println "Slave $target_slave not found!";
status = 1;
}
//}