Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make purge-build-queue-by-name.groovy more flexible #162

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion purge-build-queue-by-name.groovy
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
//Purge build queue by name

// find tasks by name which contains string pattern REPLACEME
import hudson.model.*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import hudson.model.*

This one is implicit so no need to explicitly import. Also Jenkins class is in the jenkins.model package, not in hudson.model so pointless anyway.

def q = Jenkins.instance.queue
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def q = Jenkins.instance.queue

q.items.findAll { it.task.name.startsWith('REPLACEME') }.each { q.cancel(it.task) }
q.items.findAll { it.task.name.contains('REPLACEME') }.each { println it.task.name }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
q.items.findAll { it.task.name.contains('REPLACEME') }.each { println it.task.name }
Queue.getInstance().items.findAll { it.task.name.contains('REPLACEME') }.each { println it.task.name }

Since this does not have to reuse the q to cancel task, it can be reduced to one line.


// purge
import hudson.model.*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import hudson.model.*

as above

def q = Jenkins.instance.queue
q.items.findAll { it.task.name.contains('REPLACEME') }.each { q.cancel(it.task) }