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

Alo*_*onL 14 jenkins jenkins-plugins

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

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

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

非常感谢!

Nay*_*iya 22

这是Copy>Paste>RunKeepCalmAndCarryOn答案的版本. 转到管理Jenkins>脚本控制台>复制并粘贴此代码>运行

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

在此输入图像描述

  • 哈……他说渡渡鸟 (2认同)
  • 我必须在测试中将其设为“aSlave.getComputer()?.isOffline()”。 (2认同)

Kee*_*yOn 19

这个脚本有一个注释掉的部分来删除节点.

它在Jenkins脚本控制台中运行

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());
}
Run Code Online (Sandbox Code Playgroud)