I have a similar problem, where I need to run maintenance jobs on machines with multiple nodes. I installed the Scriptler plugin and wrote these two scripts; one to disable all nodes on a given label (which lets them finish their current tasks but prevents them from taking on more jobs) and wait for them to finish (you may not need the last part), and the other to enable all nodes on that label. These scripts must be run as Scriptler jobs that are bound to the master node (so that they are in the same address space as the server).
--Rob Mandeville
---BEGIN LABEL SHUTDOWN SCRIPT---
import hudson.model.Hudson
import jenkins.model.Jenkins
import hudson.model.Computer
println "Passed in label $labelName."
label = Jenkins.instance.getLabel(labelName)
if(!label){
println("Could not find label $labelName")
}else{
nodes = label.getNodes()
for(node in nodes){
nodeName = node.getNodeName()
println("Node $nodeName is part of label $labelName")
}
}
nodeToComputer = new HashMap<Node, Computer>()
for(node in nodes){
computer = node.toComputer()
if(null == computer){
println("NO COMPUTER for node $nodeName")
}else{
nodeToComputer.put(node, computer)
}
}
for(node in nodes){
nodeName = node.getNodeName()
computer = nodeToComputer.get(node)
println("We have a computer for node $nodeName")
if(computer.isTemporarilyOffline()){
reason = computer.getOfflineCause()
println("Node $nodeName is already offline: $reason");
}else{
computer.setTemporarilyOffline(true)
println("Node $nodeName is set for offline.")
}
}
for(node in nodes){
nodeName = node.getNodeName()
computer = nodeToComputer.get(node)
print("Waiting for node $nodeName to finish...")
computer.waitUntilOffline()
while(computer.countBusy() != 0){
sleep(1000)
}
println("done");
}
---END LABEL SHUTDOWN SCRIPT---
---BEGIN LABEL STARTUP SCRIPT--
import hudson.model.Hudson
import jenkins.model.Jenkins
import hudson.model.Computer
println "Passed in label $labelName."
label = Jenkins.instance.getLabel(labelName)
if(!label){
println("Could not find label $labelName")
}else{
nodes = label.getNodes()
for(node in nodes){
nodeName = node.getNodeName()
println("Node $nodeName is part of label $labelName")
}
}
nodeToComputer = new HashMap<Node, Computer>()
for(node in nodes){
computer = node.toComputer()
if(null == computer){
println("NO COMPUTER for node $nodeName")
}else{
nodeToComputer.put(node, computer)
}
}
for(node in nodes){
nodeName = node.getNodeName()
computer = nodeToComputer.get(node)
println("We have a computer for node $nodeName")
if(computer.isTemporarilyOffline()){
computer.setTemporarilyOffline(false)
println("Setting Node $nodeName to online");
}else{
println("Node $nodeName is already online.")
}
}
for(node in nodes){
nodeName = node.getNodeName()
computer = nodeToComputer.get(node)
print("Waiting for node $nodeName to finish...")
computer.waitUntilOnline()
println("done");
}
---END LABEL STARTUP SCRIPT---
--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
jenkinsci-use...@googlegroups.com.
For more options, visit
https://groups.google.com/groups/opt_out.
The information in this message is for the intended recipient(s) only and may be the proprietary and/or confidential property of Litle & Co., LLC, and thus protected from disclosure. If you are not the intended recipient(s), or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any use, dissemination, distribution or copying of this communication is prohibited. If you have received this communication in error, please notify Litle & Co. immediately by replying to this message and then promptly deleting it and your reply permanently from your computer.