Created
August 16, 2018 23:28
-
-
Save usmansaleem/5fcfb27d2f4cbf6427abc64e3bc2f2c4 to your computer and use it in GitHub Desktop.
Cancel jenkins jobs except newest
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://stackoverflow.com/a/39635794 | |
def q = Jenkins.instance.queue | |
//Find items in queue that match <project name> | |
def queue = q.items.findAll { it.task.name.startsWith('sample_project') } | |
//get all jobs id to list | |
def queue_list = [] | |
queue.each { queue_list.add(it.getId()) } | |
//sort id's, remove last one - in order to keep the newest job, cancel the rest | |
queue_list.sort().take(queue_list.size() - 1).each { q.doCancelItem(it) } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment