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

[JENKINS-71616] Use full project name instead of related name for comparing job names #490

Open
wants to merge 2 commits 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import jenkins.model.Jenkins;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.regex.Pattern;

/**
* Class for maintaining and synchronizing the runningJobs info.
Expand Down Expand Up @@ -233,8 +234,16 @@ private void cancelMatchingJobs(GerritTriggeredEvent event, String jobName, Caus
List<Queue.Item> itemsInQueue = Queue.getInstance().getItems((Queue.Task)getJob());
for (Queue.Item item : itemsInQueue) {
if (checkCausedByGerrit(event, item.getCauses())) {
if (jobName.equals(item.task.getName())) {
// Use regexpt .*jobName to avoid
Copy link
Contributor

Choose a reason for hiding this comment

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

Item task is always an instance of hudson.model.Item I think, so you could check if this is the case and if yes cast to Item and then use getFullName() for the comparison. No need use a regex here.

// incorrect comparison in case of complicated full name
// .*\/jobName$|^jobName$

String regex = ".*\\/" + jobName + "$|^" + jobName + "$";
Pattern pattern = Pattern.compile(regex);

if (pattern.matcher(item.task.getName()).matches()) {
Queue.getInstance().cancel(item);

}
}
}
Expand Down