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

"Block build when upstream project is building" is not guaranteed to work if plugins are installed that can block projects

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • core
    • None
    • Jenkins 2.332.3
    • 2.361

      The documentation for the flag "Block build when upstream project is building" states the following: "When this option is checked, Jenkins will prevent the project from building when a dependency of this project is in the queue, or building. The dependencies include the direct as well as the transitive dependencies."

      Emphasis mine. 

      In the following minimal example a project is built even though a direct dependency is currently in the queue:

      ┌──A
      │  │
      │  ▼
      │  B
      │  │
      │  ▼
      └─►C 

      After A has finished, C runs immediately even though B is in the queue thus contradicting the documentation. 

      After looking into the code, I think I found the source of this problem: 

      The Queue-class depends on AbstractProject.getCauseOfBlockage() to check if a project may run. Within getCauseOfBlockage() the state of the flag "Block build when upstream project is building" is evaluated. If the flag is set, AbstractProject.getBuildingUpstream() is checked. Within getBuildingUpstream() the following method is called Jenkins.get().getQueue().getUnblockedTasks(). Queue.getUnblockedTasks() only returns projects from Queue.waitingList, Queue.buildable, and Queue.pending. No projects from Queue.blockedProjects are returned. Thus, even though B is in the queue, it does not prevent C from building, since B is blocked.

      If no external plugin is installed that introduces additional blocking behavior (such as the build-blocker-plugin), the flags would work as documented, since blocked projects can be safely disregarded, because AbstractProject.getBuildingUpstream() will return at least one project in the state of waiting/buildable/pending/building (since this is the only reason for a blocked project). 

      I am not sure if this bug can be fixed since fixing it would almost certainly require changing the behavior of API methods from Queue (and thus would risk breaking existing plugins). 

      My suggestion would be to change the documentation for the flags: 
      "When this option is checked, Jenkins will prevent the project from building when a dependency of this project is in the queue, or building. The dependencies include the direct as well as the transitive dependencies. This behavior is not guaranteed to work if plugins are installed that may block projects from running."

            Unassigned Unassigned
            simon_sohrt Simon Sohrt
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: