Jenkins - 有没有办法删除所有脱机节点(从属)/批量删除节点/删除所有节点?

时间:2014-06-06 00:26:24

标签: jenkins jenkins-plugins

使用Jenkins Docker插件时,可能是因为错误,无法启动群集。我没有注意,目前我有数以千计的离线节点,但未能启动。

BOTTOM LINE - 有没有办法批量删除Jenkin中的节点(从属),清理所有脱机节点甚至删除所有节点?重申Jenkins服务器没有帮助,我在Jenkins API中找不到方法。

在我开始编写Selenium脚本之前,我会欣赏任何想法......

非常感谢!

3 个答案:

答案 0 :(得分:18)

这个script有一个注释掉的部分用于删除节点。

它在Jenkins script console

中运行
for (aSlave in hudson.model.Hudson.instance.slaves) {
  println('====================');
  println('Name: ' + aSlave.name);
  println('getLabelString: ' + aSlave.getLabelString());
  println('getNumExectutors: ' + aSlave.getNumExecutors());
  println('getRemoteFS: ' + aSlave.getRemoteFS());
  println('getMode: ' + aSlave.getMode());
  println('getRootPath: ' + aSlave.getRootPath());
  println('getDescriptor: ' + aSlave.getDescriptor());
  println('getComputer: ' + aSlave.getComputer());
  println('\tcomputer.isAcceptingTasks: ' + aSlave.getComputer().isAcceptingTasks());
  println('\tcomputer.isLaunchSupported: ' + aSlave.getComputer().isLaunchSupported());
  println('\tcomputer.getConnectTime: ' + aSlave.getComputer().getConnectTime());
  println('\tcomputer.getDemandStartMilliseconds: ' + aSlave.getComputer().getDemandStartMilliseconds());
  println('\tcomputer.isOffline: ' + aSlave.getComputer().isOffline());
  println('\tcomputer.countBusy: ' + aSlave.getComputer().countBusy());
  //if (aSlave.name == 'NAME OF NODE TO DELETE') {
  //  println('Shutting down node!!!!');
  //  aSlave.getComputer().setTemporarilyOffline(true,null);
  //  aSlave.getComputer().doDoDelete();
  //}
  println('\tcomputer.getLog: ' + aSlave.getComputer().getLog());
  println('\tcomputer.getBuilds: ' + aSlave.getComputer().getBuilds());
}

答案 1 :(得分:15)

这是KeepCalmAndCarryOn答案的Copy>Paste>Run版本。 去管理Jenkins>脚本控制台>副本&粘贴此代码>运行

for (aSlave in hudson.model.Hudson.instance.slaves) {
    if (aSlave.getComputer().isOffline()) {
        aSlave.getComputer().setTemporarilyOffline(true,null);
        aSlave.getComputer().doDoDelete();
    }
}

enter image description here

答案 2 :(得分:0)

感谢您的回答。

另一种方法是手动编辑' $ {JENKINS_HOME} /config.xml'文件(例如,通过正则表达式查找/替换)。

相关问题