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

next-executions: Support evenly distributed crontab

    Details

    • Similar Issues:

      Description

      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;					
       				}
      

        Attachments

          Activity

          Hide
          scm_issue_link SCM/JIRA link daemon added a comment -

          Code changed in jenkins
          User: Ignacio Albors
          Path:
          src/main/java/hudson/plugins/nextexecutions/utils/NextExecutionsUtils.java
          http://jenkins-ci.org/commit/next-executions-plugin/51fa26639a9ed58b78ef3e1bd9330891c8521cec
          Log:
          Fixed JENKINS-12676.

          Get the next builds through Java reflection.

          Thanks to OHTAKE Tomohiro for patch.

          Show
          scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Ignacio Albors Path: src/main/java/hudson/plugins/nextexecutions/utils/NextExecutionsUtils.java http://jenkins-ci.org/commit/next-executions-plugin/51fa26639a9ed58b78ef3e1bd9330891c8521cec Log: Fixed JENKINS-12676 . Get the next builds through Java reflection. Thanks to OHTAKE Tomohiro for patch.

            People

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

              Dates

              • Created:
                Updated:
                Resolved: