Is there a way to detect in a certain job by example running on the master) to check if the slaves needed for the next buildsteps are online?
I would want the master job to fail and don't start any next build if not all needed slave nodes are online.
Visit a url like http:``//myslave:3141 to see whether a slave is running and how much memory it is using. Configure the port used by clicking Manage Jenkins on the dashboard.
Visit "Manage Jenkins" > "Manage Nodes". Select any node to view the status page. In the menu on the left, a menu item is available to open a "Script Console" on that specific agent.
Jenkins slaves connect to the Jenkins master using the Java Network Launch Protocol.
Here's a Groovy script that could do it. It needs to be in a "System Groovy Script" build step. The last line determines the script's return status, and a non-zero status will cause the script to return failure, which will fail the job.
import hudson.model.*
def requiredNodes = ['one','two','three'];
def status = 0;
for (node in requiredNodes) {
println "Searching for $node";
slave = Hudson.instance.slaves.find({it.name == node});
if (slave != null) {
computer = slave.getComputer();
if (computer.isOffline()) {
println "Error! $node is offline.";
status = 1;
}
else {
println "OK: $node is online";
}
}
else {
println "Slave $node not found!";
status = 1;
}
}
status;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With