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

Support multiple time zones in cron expression

      I tried to report this via the email list, but my email bounced, so let me report it here:

      Currently, If I want to schedule a job to run at 7am in NYC time, I can easily do this by syntax that resembles this:

      TZ=America/New_York
      0 7 * * *
      

      If I want to instead run it at 7am London time, then I can change the first line to London instead of NYC and it still works.
      Ideally, I should be able to run it at 7am in BOTH time zones (that is, twice a day in total).
      The natural syntax would be:

      TZ=America/New_York
      0 7 * * *
      TZ=Europe/London
      0 7 * * *
      

      This syntax is of course not accepted, but it seems that it easily could be.
      It seems that all we need is to remove the "line number == 1" check on line 115, here:
      https://github.com/jenkinsci/jenkins/blame/master/core/src/main/java/hudson/scheduler/CronTabList.java#L115

      The only alternative is to create “wrapper” jobs, one for each time zone you care about, whose sole purpose is to invoke the “real” one.
      This is not nice because it creates clutter in the list of jobs, and also is not newbie friendly.
      I’m a Jenkins newbie myself (first “real” exposure to Jenkins was a few weeks ago) and so far I can’t even figure out HOW to create wrappers.
      Should I be using the “freestyle” jobs? Multi job? Pipeline? Something else?

          [JENKINS-73809] Support multiple time zones in cron expression

          Markus Winter added a comment -

          You can use https://plugins.jenkins.io/extended-timer-trigger/

          Besides allowing to use an extended syntax it also fully supports the regular syntax and you can specify the timezone anywhere

          Markus Winter added a comment - You can use https://plugins.jenkins.io/extended-timer-trigger/ Besides allowing to use an extended syntax it also fully supports the regular syntax and you can specify the timezone anywhere

          Mark added a comment -

          Thanks. As far as I can see, that one doesn't support parameters, like the parameterized plugin does.
          For each time zone I'm passing different parameters.

          Mark added a comment - Thanks. As far as I can see, that one doesn't support parameters, like the parameterized plugin does. For each time zone I'm passing different parameters.

          Markus Winter added a comment -

          OK, so that means it is not only core but also that plugin that needs this enhancement

          Markus Winter added a comment - OK, so that means it is not only core but also that plugin that needs this enhancement

          Mark added a comment -

          I assumed they share a parser but on second thought I should have realized that's unlikely

          Mark added a comment - I assumed they share a parser but on second thought I should have realized that's unlikely

          Mark added a comment -

          Also: this should be a separate ticket but maybe I'll mention it here: it would be cool it the hash feature supported an offset, so that instead of doing this:

          @hourly % CMD_LINE=one
          @hourly % CMD_LINE=two
          

          I could do this

          # not sure about syntax here; needs bike shedding
          H+00 * * * * % CMD_LINE=one
          H+30 * * * * % CMD_LINE=two
          

          And this would implicitly do math modulo 60.
          (So if H is 33, the first job would run at 33 min past the hour, and the second would run at 3 minutes past the hour)
          I could do this by hand by grabbing my calculator and picking a random number, but the whole point of the hash system is that I shouldn't have to.

          Mark added a comment - Also: this should be a separate ticket but maybe I'll mention it here: it would be cool it the hash feature supported an offset, so that instead of doing this: @hourly % CMD_LINE=one @hourly % CMD_LINE=two I could do this # not sure about syntax here; needs bike shedding H+00 * * * * % CMD_LINE=one H+30 * * * * % CMD_LINE=two And this would implicitly do math modulo 60. (So if H is 33, the first job would run at 33 min past the hour, and the second would run at 3 minutes past the hour) I could do this by hand by grabbing my calculator and picking a random number, but the whole point of the hash system is that I shouldn't have to.

          Mark added a comment -

          I just noticed that a similar issue was already reported so I added a duplicate link so it's findable from here and vice versa

          Mark added a comment - I just noticed that a similar issue was already reported so I added a duplicate link so it's findable from here and vice versa

            Unassigned Unassigned
            marky_b Mark
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: