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

Conversation

Mkoz
Copy link

@Mkoz Mkoz commented Jul 10, 2023

https://issues.jenkins.io/browse/JENKINS-71616

If project has complicated name like folder/project-name then buildCurrentPatchesOnly feature does not work because of cancelMatchingJobs gets parametr jobName as full name but for comparing it uses just relative name without folder or parent project item.task.getName()).

Cannot get fullName form the task. Workaround is transform fullDisplayName with replacing separator from " » "to "/"
item.task.getFullDisplayName().replace(" » ", "/")

Don't have any idea how to prepare tests, looks like test implementation requires much more time then fix.

Testing done

Submitter checklist

Edit tasklist title
Beta Give feedback Tasklist Submitter checklist, more options

Delete tasklist

Delete tasklist block?
Are you sure? All relationships in this tasklist will be removed.
  1. Make sure you are opening from a topic/feature/bugfix branch (right side) and not your main branch!
    Options
  2. Ensure that the pull request title represents the desired changelog entry
    Options
  3. Please describe what you did
    Options
  4. Link to relevant issues in GitHub or Jira
    Options
  5. Link to relevant pull requests, esp. upstream and downstream changes
    Options
  6. Ensure you have provided tests - that demonstrates feature works or fixes the issue
    Options

@rsandell rsandell changed the title Fix JENKINS-71616, Use full project name istead of related name for comparing job names [JENKINS-71616] Use full project name istead of related name for comparing job names Jul 18, 2023
@rsandell rsandell changed the title [JENKINS-71616] Use full project name istead of related name for comparing job names [JENKINS-71616] Use full project name instead of related name for comparing job names Jul 18, 2023
// Use transformed fullDisplayNameFor to avoid
// ambigous comparing between same name projects but located at different folders
// FolderName » jobName to FolderName/jobName
if (jobName.equals(item.task.getFullDisplayName().replace(" » ", "/"))) {
Copy link
Member

Choose a reason for hiding this comment

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

The problem here is that the displayName can be anything and change almost at any time and doesn't need to be anything like jobName that is gained from getName/getFullName

Copy link
Author

Choose a reason for hiding this comment

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

Another option is change the strict comparison between jobNames to regexp something like ".*jobName$"
But in this case we will have collision with projects located at the different projects folders with same names. This is quite less possible scenario, then I'm going to fix.
@rsandell what do you think is it ok to fix it this way?

@Mkoz
Copy link
Author

Mkoz commented Aug 21, 2023

@rsandell could you please have a look to the last change?

Copy link
Member

@rsandell rsandell left a comment

Choose a reason for hiding this comment

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

Looks like the lesser evil for this issue.
Could you provide some tests for it as well please?

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

@panicking
Copy link
Contributor

panicking commented Feb 18, 2024

@rsandell Found the same and I have a fix for this in my pull request too. According to what I understand the comparison can be done differently.

https://github.com/jenkinsci/gerrit-trigger-plugin/pull/504/files#diff-95fd3211a11fb642a1d021eb51ac0c1b45cd3cecff8d0f106520b24e676c480e

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