Instantly share code, notes, and snippets.

Embed
What would you like to do?
Kill all queued jenkins jobs
import hudson.model.*
def q = Jenkins.instance.queue
q.items.each {
if (it =~ /deploy-to/) {
q.cancel(it.task)
}
}
import hudson.model.*
def q = Jenkins.instance.queue
q.items.each { q.cancel(it.task) }
@jcosmo

This comment has been minimized.

jcosmo commented May 31, 2017

Kill all 'queued deploy' jobs:

import hudson.model.*

def q = Jenkins.instance.queue

q.items.each { 
  if (it =~ /deploy-to/) {
  	q.cancel(it.task)
  }
}
@fornullinbreak

This comment has been minimized.

fornullinbreak commented Nov 27, 2018

why not just

import hudson.model.*
def queue = Hudson.instance.queue
println "Queue contains ${queue.items.length} items"
queue.clear()
println "Queue cleared"

src: https://github.com/jenkinsci/jenkins-scripts/blob/master/scriptler/clearBuildQueue.groovy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment