All!! Let's say I have Jenkins with few slave nodes (Slave1, Slave2 & Slave3). Each slave have few labels associated with it, i.e Slave1 (test build python), Slave2 (develop update clean)...
I'm looking for groovy script that I can run from Jenkins Script Console to modify labels on given slaves at once by adding/removing "-offline" suffix for each label on each slave, i.e Slave1 will have (test-offline build-offline python-offline) & Slave2 (develop-offline update-offline clean-offline).
I need this functionality in order to prevent next job start running on these slaves (let's say I want to set them offline for maintenance, once all jobs finished on these nodes). And once I done with maintenance on these slaves, I need to run another groovy script which set back all labels as they was configured before, i.e Slave1 (test build python), Slave2 (develop update clean).
So far I've found old topic about similar issue. The bellow code can return all labels for chosen slave, but its adding "offline" as additional label and not as a suffix for each existing label:
hudson = hudson.model.Hudson.instance
hudson.slaves.findAll { it.nodeName.equals("slave1") }.each { slave ->
print "Slave $slave.nodeName : Labels: $slave.labelString"
slave.labelString = slave.labelString + " " + "offline"
println " --> New labels: $slave.labelString"
}
hudson.save()
So I have few questions:
- How to use list of nodes (slave1,slave2, slave3...) and not single node slave1
- How to add/remove"-offline" suffix to/from labels? It can be two different script for adding and removing labels suffix.
Any help & suggestions are much appreciated.
Regrads, Igor.