Issue
You want to purge the build queue removing all the queued builds, or specifically remove some of them by name.
Resolution
The builds in the build queue can be cancelled from the Jenkins UI by manually clicking on the red "x" icon next to each build. If you would like to cancel all of them, or only the ones matching a specific criteria, you can use the Script Console to do so.
Administrators can access the script console under or at INSTANCE_URL/script.
-
In order to clean all pending builds from the queue, you can run the following in the script console:
Jenkins.get().queue.clear()
-
To remove only some of them, you can use the below script to purge the build queue by build name:
def q = Queue.instance q.items.findAll { it.task.name.startsWith('REPLACEME') }.each { q.cancel(it.task) }
Depending on the build queue size and the instance performance, this operation may take longer than expected, so you may want to collect Required Data: CloudBees CI hang or high CPU on Kubernetes or Linux |
If you are having difficulty starting Jenkins due to a large build queue, you can refer to our How can I prevent jenkins from starting new jobs after a restart? article to prevent Jenkins from automatically starting queued jobs.