Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-46759

Pipeline build parts does not show up in build queue for views which filters build queue

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved (View Workflow)
    • Priority: Minor
    • Resolution: Fixed
    • Component/s: core
    • Labels:
    • Environment:
      jenkins 2.77
    • Similar Issues:

      Description

      Noticed this one the other day, if you have a pipeline job with build parts in the queue and you're looking at a view with the filter build queue option, then the build part doesn't show up in the build queue.

      Notice how the build queue is empty in the second image while there clearly is a build part queued for the job test in the main view.

      The problem is that, in hudson.model.View#filterQueue(List<Queue.Item> base), it only checks if the queue task is in the list of filtered jobs, however that is not true for pipeline parts as the task is a step and not the job it self. To solve this, simply also check if Queue.Task#getOwnerTask() is in the list of filtered jobs (do this recursively).

      I will make a pull request for this, only problem is how to write a test for this, doesn't seem like there are any existing similar tests for views

      Suggestions and alternative solutions are welcome 

        Attachments

          Activity

          Hide
          jons Jon Sten added a comment -

          This code should do the trick:

          private List<Queue.Item> filterQueue(List<Queue.Item> base) {
              if (!isFilterQueue()) {
                  return base;
              }
          
              Collection<TopLevelItem> items = getItems();
              List<Queue.Item> result = new ArrayList<Queue.Item>();
              for (Queue.Item qi : base) {
                  // Check if the task of parent tasks are in the list of items.
                  // Pipeline jobs and other jobs which allow parts require us to
                  // check owner tasks as well.
                  Queue.Task currentTask = null;
                  do {
                      currentTask = currentTask == null ? qi.task : currentTask.getOwnerTask();
                      if (items.contains(currentTask)) {
                          result.add(qi);
                          break;
                      }
                  } while (currentTask.getOwnerTask() != currentTask);
                  // Check root project for sub-job projects (e.g. matrix jobs).
                  if (qi.task instanceof AbstractProject<?, ?>) {
                      AbstractProject<?,?> project = (AbstractProject<?, ?>) qi.task;
                      if (items.contains(project.getRootProject())) {
                          result.add(qi);
                      }
                  }
              }
              return result;
          }
          
          Show
          jons Jon Sten added a comment - This code should do the trick: private List<Queue.Item> filterQueue(List<Queue.Item> base) { if (!isFilterQueue()) { return base; } Collection<TopLevelItem> items = getItems(); List<Queue.Item> result = new ArrayList<Queue.Item>(); for (Queue.Item qi : base) { // Check if the task of parent tasks are in the list of items. // Pipeline jobs and other jobs which allow parts require us to // check owner tasks as well. Queue.Task currentTask = null; do { currentTask = currentTask == null ? qi.task : currentTask.getOwnerTask(); if (items.contains(currentTask)) { result.add(qi); break; } } while (currentTask.getOwnerTask() != currentTask); // Check root project for sub-job projects (e.g. matrix jobs). if (qi.task instanceof AbstractProject<?, ?>) { AbstractProject<?,?> project = (AbstractProject<?, ?>) qi.task; if (items.contains(project.getRootProject())) { result.add(qi); } } } return result; }
          Show
          jons Jon Sten added a comment - PR:  https://github.com/jenkinsci/jenkins/pull/3008
          Hide
          scm_issue_link SCM/JIRA link daemon added a comment -

          Code changed in jenkins
          User: Jon
          Path:
          core/src/main/java/hudson/model/View.java
          core/src/test/java/hudson/model/MockItem.java
          core/src/test/java/hudson/model/ViewTest.java
          http://jenkins-ci.org/commit/jenkins/ce2d0f97bdbb5fb171443559d210dffef7961dc2
          Log:
          JENKINS-46759 Fixed bug in build queue filtering for views (#3008)

          • JENKINS-46759 Fixed bug related to views which filters build queue, jobs which has multiple sub steps were filtered incorrectly.
          • Added test case for build queue filtering in views.
          • JENKINS-46759 Improved code based on feedback from PR; Fixed logic bug, moved logic to separate method and added limit to number of iteration when looking for owner task.
          Show
          scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Jon Path: core/src/main/java/hudson/model/View.java core/src/test/java/hudson/model/MockItem.java core/src/test/java/hudson/model/ViewTest.java http://jenkins-ci.org/commit/jenkins/ce2d0f97bdbb5fb171443559d210dffef7961dc2 Log: JENKINS-46759 Fixed bug in build queue filtering for views (#3008) JENKINS-46759 Fixed bug related to views which filters build queue, jobs which has multiple sub steps were filtered incorrectly. Added test case for build queue filtering in views. JENKINS-46759 Improved code based on feedback from PR; Fixed logic bug, moved logic to separate method and added limit to number of iteration when looking for owner task.

            People

            • Assignee:
              jons Jon Sten
              Reporter:
              jons Jon Sten
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: