我们的Jenkins服务器有一个已经运行了三天的作业,但是没有做任何事情。单击角落里的小X没有任何作用,控制台输出日志也没有显示任何内容。我在我们的构建服务器上检查过,该作业实际上似乎根本没有在运行。

有没有办法告诉jenkins工作已经“完成”了,比如编辑一些文件或锁之类的?因为我们有很多任务,所以我们并不想重新启动服务器。


当前回答

非常简单的解决方案

我看到这个问题的原因是页面上不正确的http链接,而不是应该停止工作的https。所有你需要做的是编辑onclick属性在html页面,通过以下

Open up a console log of the job (pipeline) that got hang Click whatever is available to kill the job (x icon, "Click here to forcibly terminate running steps" etc) to get "Click here to forcibly kill entire build" link visible (it's NOT gonna be clickable at the moment) Open the browser's console (use any one of three for chrome: F12; ctrl + shift + i; menu->more tools->developer tools) Locate "Click here to forcibly kill entire build" link manually or using "select an element in the page" button of the console Double click on onclick attribute to edit its value Append s to http to have https Press enter to submit the changes Click "Click here to forcibly kill entire build" link

使用截图作为参考

其他回答

进入"Manage Jenkins" > "Script Console"在服务器上运行一个脚本以中断挂起的线程。

您可以使用Thread.getAllStackTraces()获取所有活动线程,并中断正在挂起的线程。

Thread.getAllStackTraces().keySet().each() {
  t -> if (t.getName()=="YOUR THREAD NAME" ) {   t.interrupt();  }
}

更新:

上述使用线程的解决方案可能不适用于最新的Jenkins版本。要中断冻结的管道,请参考这个解决方案(由alexandru-bantiuc),并运行:

Jenkins.instance.getItemByFullName("JobName")
                .getBuildByNumber(JobNumber)
                .finish(
                        hudson.model.Result.ABORTED,
                        new java.io.IOException("Aborting build")
                );

同样的问题已经发生在我身上两次了,唯一的解决方案是重新启动tomcat服务器并重新启动构建。

最近我遇到了一个节点/代理,它的一个执行程序被管道作业的构建“X”占用了几天,尽管该作业页面声称构建“X”不再存在(在后续10个构建后被丢弃(!),正如管道作业中配置的那样)。在磁盘上验证:构建“X”真的消失了。

解决方案:代理/节点错误地报告了被占用的执行程序正在忙着运行构建“X”。中断该执行程序的线程会立即释放它。

def executor = Jenkins.instance.getNode('NODENAME').computer.executors.find {
    it.isBusy() && it.name.contains('JOBNAME')
}

println executor?.name
if (executor?.isBusy()) executor.interrupt()

考虑的其他答案:

来自@cheffe的答案:没有工作(见下一点,并在下面更新)。 thread. getallstacktraces()的答案:没有匹配的线程。 来自@levente-holló的答案和getBuildByNumber()的所有答案:不适用,因为构建已经不存在了! 来自@austinfromboston的答案:这接近于我的需求,但它也会破坏目前正在运行的任何其他构建。

更新: 我再次经历了类似的情况,Executor被一个(仍然存在的)已完成的管道构建占用了数天。这个代码片段是唯一可行的解决方案。

如果你有一个不可阻挡的管道作业,试试下面的方法:

通过单击构建进度条旁边的红色X来终止作业 点击构建上的“Pause/resume”暂停 再次单击“暂停/恢复”以恢复构建

Jenkins将意识到该作业应该终止并停止构建

我也有同样的问题,并修复它通过詹金斯控制台。

进入“Manage Jenkins”>“Script Console”,运行一个脚本:

 Jenkins .instance.getItemByFullName("JobName")
        .getBuildByNumber(JobNumber)
        .finish(hudson.model.Result.ABORTED, new java.io.IOException("Aborting build")); 

您只需指定JobName和JobNumber。