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

next-executions: Support evenly distributed crontab

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • next-executions-plugin
    • None
    • Next Executions 1.03
      Jenkins 1.450

      Jenkins 1.448 added a new feature for crontab to distribute crontab evenly.
      See https://github.com/jenkinsci/jenkins/commit/b1bb3f66676b550971db08725d5c3cef5b42191b.

      The issue is that next execution plugin does not support the new feature.
      For instance, if a job is configured as crontab @daily,
      next executions plugin says that the next will be 09/02/2012 00:00.
      But actual next execution might be 09/02/2012 12:34 or 09/02/2012 01:23.

      An unsafe workaround is to read private fiels of Trigger and CronTabList.

      NextExecutionsUtils.java
      @@ -25,9 +27,23 @@ public static NextBuilds getNextBuild(AbstractProject project){
       		if(!project.isDisabled()){
       			Trigger trigger = project.getTrigger(TimerTrigger.class);
       			if(trigger != null){
      -				List<CronTab> crons = parseSpec(trigger.getSpec());
      +				Vector<CronTab> tabs;
      +				try {
      +					Field fieldTriggerTabs = Trigger.class.getDeclaredField("tabs");
      +					fieldTriggerTabs.setAccessible(true);
      +					Field fieldCronTabListTabs = CronTabList.class.getDeclaredField("tabs");
      +					fieldCronTabListTabs.setAccessible(true);
      +					CronTabList crontablist = (CronTabList)fieldTriggerTabs.get(trigger);
      +					tabs = (Vector<CronTab>) fieldCronTabListTabs.get(crontablist);
      +				} catch (NoSuchFieldException ex) {
      +					ex.printStackTrace();
      +					throw new NoSuchFieldError();
      +				} catch (IllegalAccessException ex) {
      +					ex.printStackTrace();
      +					throw new IllegalAccessError();
      +				}
       				Calendar cal = null;
      -				for (CronTab cronTab : crons) {
      +				for (CronTab cronTab : tabs) {
       					Date d = new Date();				
       					cal = (cal == null || cal.compareTo(cronTab.ceil(d.getTime())) > 0)? cronTab.ceil(d.getTime()) : cal;					
       				}
      

            ialbors Ignacio Albors
            ohtake_tomohiro OHTAKE Tomohiro
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: