1

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();
  }
}
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
  • This has nothing to do with the objective content particular question; But when do people learn, how to [state a proper](https://stackoverflow.com/help/how-to-ask) question? This includes a meaningful topic, proper text in the question itself as well as a [Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve). – jhoepken Sep 15 '17 at 09:47

1 Answers1

1

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;
  }
}