使用 Groovy for Jenkins 取消排队构建并中止执行构建 [英] Cancel queued builds and aborting executing builds using Groovy for Jenkins

查看:41
本文介绍了使用 Groovy for Jenkins 取消排队构建并中止执行构建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于使用 Groovy 系统脚本的 Jenkins,是否有一种方法可以轻松搜索构建队列和针对某些条件(特别是匹配某些条件的参数)的执行构建列表,然后杀死/取消它们?

For Jenkins using a Groovy System Script, is there a way to easily search the build queue and list of executing builds for some criteria (specifically a parameter that matches some condition) and then kill/cancel them?

我似乎找不到任何方法来做到这一点,但看起来应该是可能的.

I cannot seem to find any way to do this, but it seems like it should be possible.

推荐答案

我自己没有测试过,但是查看了 API 应该可以通过以下方式实现:

I haven't tested it myself, but looking at the API it should be possible in the following way:

import hudson.model.*
import jenkins.model.Jenkins

def q = Jenkins.instance.queue

q.items.findAll { it.task.name.startsWith('my') }.each { q.cancel(it.task) }

相关 API 链接:

这篇关于使用 Groovy for Jenkins 取消排队构建并中止执行构建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆