-
Notifications
You must be signed in to change notification settings - Fork 411
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
base: master
Are you sure you want to change the base?
Make purge-build-queue-by-name.groovy more flexible #162
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let us polish it a bit. I suggested some changes. WDYT?
@@ -1,5 +1,11 @@ | |||
//Purge build queue by name | |||
|
|||
// find tasks by name which contains string pattern REPLACEME | |||
import hudson.model.* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
q.items.findAll { it.task.name.contains('REPLACEME') }.each { println it.task.name } | ||
|
||
// purge | ||
import hudson.model.* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import hudson.model.* |
as above
import hudson.model.* | ||
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 } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
@@ -1,5 +1,11 @@ | |||
//Purge build queue by name | |||
|
|||
// find tasks by name which contains string pattern REPLACEME | |||
import hudson.model.* | |||
def q = Jenkins.instance.queue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def q = Jenkins.instance.queue |
Changed startsWith to contains. Added a sample query first.