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.
The builds in the pending queue can be easily cancelled from the Jenkins UI by manually clicking on the red "x" icon next to each build.
This feature can be accessed from "Manage Jenkins" > "Script Console". Or by visiting the sub-URL /script on your Jenkins instance.
Rather than stopping Jenkins, you can put it into "Quiet Down" mode, which prevents any new builds from taking place. You can enable this via the URLs /quietDown and /cancelQuietDown , or via the CLI commands [cancel-]quiet-down . – Christopher Orr.
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) }
Relevant API links:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With