How to lock and unlock jenkins slave with groovy?

520 views Asked by At

How can I lock and unlock Jenkins slave? Pseudo code like this.

for (slave in hudson.model.Hudson.instance.slaves) {
  if (slave.getNodeName() == "slave_need_to_be_lock") {
    Computer c = slave.getComputer();
    c.lock();
    c.unlock();
  }
}
1

There are 1 answers

0
user2749607 On

I work it out with following code.

for (slave in hudson.model.Hudson.instance.slaves) {
  if (slave.getNodeName() == "slave_need_to_be_lock") {
    Computer c = slave.getComputer();
    c.disconnect(); //Just like lock;
    c.connect(false); //Just like unlock;
  }
}