Usage of @Initializer(after = InitMilestone.COMPLETED) in plugins breaks the initialization logic

This issue is archived. You can view it, but you can't modify it. Learn more

XMLWordPrintable

      The problem is in the Initializer code:

      /**
           * Indicates that the specified milestone is necessary before executing this initializer.
           *
           * <p>
           * This has the identical purpose as {@link #requires()}, but it's separated to allow better type-safety
           * when using {@link InitMilestone} as a requirement (since enum member definitions need to be constant.)
           */
          InitMilestone after() default STARTED;
      
          /**
           * Indicates that this initializer is a necessary step before achieving the specified milestone.
           *
           * <p>
           * This has the identical purpose as {@link #attains()}. See {@link #after()} for why there are two things
           * to achieve the same goal.
           */
          InitMilestone before() default COMPLETED;
      

      If an initializer overrides <code>after</code> as COMPLETED, hence we end up in the situation when (<code>before == after == COMPLETED</code>). In such case Jenkins' reactor can never succeed in the canRun() check, and finally we do not invoke "Initialization completed" milestone since the code requires the dependency to be executed. So we get into chicken-and-egg

      Sample script for the issue analysis:

      import hudson.init.InitMilestone; 
      import hudson.util.HttpResponses;
      import javax.servlet.http.HttpServletResponse;
      
      final Jenkins jenkins = Jenkins.getInstance();
      
      if (jenkins.getInitLevel().compareTo(InitMilestone.COMPLETED) < 0) {
        println "Error: Jenkins initialization has not reached the COMPLETED state. Current state is ${jenkins.getInitLevel()}"
        return HttpResponses.status(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
      }
      

      Examples:

      Proposed changes:

      • Add injected test, which verifies the startup InitMilestone of Jenkins
      • Make Jenkins robust against wrong definitions
      • Finally add support of Initializers after COMPLETED by introducing a transient milestone

            Assignee:
            Oleg Nenashev
            Reporter:
            Oleg Nenashev
            Archiver:
            Jenkins Service Account

              Created:
              Updated:
              Resolved:
              Archived: