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

Conversation

cbdchang
Copy link

Changed startsWith to contains. Added a sample query first.

@cbdchang cbdchang requested a review from duemir March 2, 2021 23:27
Copy link
Member

@duemir duemir left a 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.*
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.

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

// 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

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 }
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.

@@ -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
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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants