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

Add ability to specify parameters in the crontab

      I was missing the possibility to pass a parameter to a crontab line, so that I can do different things on different days.

      e.g.
      We have a linux that is built every day except Saturdays (~1h) and on Sundays we run a clean build (~10h), where Saturday is reserved for other projects that run a clean build.
      The only way for me was to create a conditional build step. It blows up the job configuration and gets decoupled from the crontab:
      So when someone changes the crontab from Sunday to Saturday for clean builds, he will also have to change the day in the conditional build step.

      My proposal is to extend the crontab syntax by something like:

      MIN HOUR DOM MONTH DOW % PARAM1=VALUE1,PARAM2=VALUE2

      This would than schedule a build with the given parameters.

      Would others be interested too?

          [JENKINS-16352] Add ability to specify parameters in the crontab

          James Wilson added a comment -

          Here's a first pass at solving this. I have the approach that most additions should be plugins. When I looked at the Trigger extension point I was sceptical that this should be a plugin. The CronTab and CronTabList classes did not want to cooperate.

          Then there is the is the configuration. In order to make the parameterized schedule enabled only for projects with parameters I seem to have forced the user to re-enter the config screen after setting parameters. This does not flow well.

          Now that I've implemented it as a plugin, I suspect it should be in core. Else the Trigger extension point needs some refactoring to support different kinds of triggers. It's my opinion that the Trigger was nearly already in need of refactoring. This is evidenced by Trigger.getSpec(), checkTriggers is static but other Trigger implementations may not be the least bit interested in CronTabList. For my part, I needed to extend CronTab to support parameters stored with each.

          I'm interested to hear the opinion of others closer to, with more experience in, the jenkins-core.

          https://github.com/jwmach1/parameterized-scheduler

          James Wilson added a comment - Here's a first pass at solving this. I have the approach that most additions should be plugins. When I looked at the Trigger extension point I was sceptical that this should be a plugin. The CronTab and CronTabList classes did not want to cooperate. Then there is the is the configuration. In order to make the parameterized schedule enabled only for projects with parameters I seem to have forced the user to re-enter the config screen after setting parameters. This does not flow well. Now that I've implemented it as a plugin, I suspect it should be in core. Else the Trigger extension point needs some refactoring to support different kinds of triggers. It's my opinion that the Trigger was nearly already in need of refactoring. This is evidenced by Trigger.getSpec(), checkTriggers is static but other Trigger implementations may not be the least bit interested in CronTabList. For my part, I needed to extend CronTab to support parameters stored with each. I'm interested to hear the opinion of others closer to, with more experience in, the jenkins-core. https://github.com/jwmach1/parameterized-scheduler

          Daniel Beck added a comment -

          Wouldn't it be better to have this logic in the build script?

          Even if this were added, it's very likely the next person wants to run arbitrary scripts because the rules he needs to implement are more complicated.

          Daniel Beck added a comment - Wouldn't it be better to have this logic in the build script? Even if this were added, it's very likely the next person wants to run arbitrary scripts because the rules he needs to implement are more complicated.

          James Wilson added a comment -

          If I can still schedule a build that has non-default build parameters, cool. The use case I have is with around a dozen projects, each needs to build with different parameters (one of the parameters is for what environment to test against) for different times of the day/week. Creating a non-parameterized build for each project, for each of the different parameter combinations is an administrative nightmare

          James Wilson added a comment - If I can still schedule a build that has non-default build parameters, cool. The use case I have is with around a dozen projects, each needs to build with different parameters (one of the parameters is for what environment to test against) for different times of the day/week. Creating a non-parameterized build for each project, for each of the different parameter combinations is an administrative nightmare

          Daniel Beck added a comment -

          The use case I have is with around a dozen projects, each needs to build with different parameters (one of the parameters is for what environment to test against) for different times of the day/week.

          What I mean is, don't make these parameters that only depend on date/time in Jenkins. Let the job be parameterless (or at least without these parameters), and determine day of week in the build script and adapt behavior there.

          Daniel Beck added a comment - The use case I have is with around a dozen projects, each needs to build with different parameters (one of the parameters is for what environment to test against) for different times of the day/week. What I mean is, don't make these parameters that only depend on date/time in Jenkins. Let the job be parameterless (or at least without these parameters), and determine day of week in the build script and adapt behavior there.

          Ed Abshire added a comment -

          We are using Jenkins as an orchestration engine to kick off tasks. We have a common task shared across multiple teams that just varies by parameters. For scheduling, this would be really nice for us to be able to let our users schedule their task with the parameters for their tests and have it kick off when they want at a set time.

          Ed Abshire added a comment - We are using Jenkins as an orchestration engine to kick off tasks. We have a common task shared across multiple teams that just varies by parameters. For scheduling, this would be really nice for us to be able to let our users schedule their task with the parameters for their tests and have it kick off when they want at a set time.

          danielbeck just found this issue and the plugin above.

          > Let the job be parameterless (or at least without these parameters), and determine day of week in the build script and adapt behavior there.

          Actually, for the use case that led me here, that wouldn't seem doable: in our situation, people who are going to specify those values aren't developers/very technical. It's far easier to ask them to specify cron + param=value form than to twiddle with shell-scripting. So I'd personnally like to consider this plugin get forked.

          Baptiste Mathus added a comment - danielbeck just found this issue and the plugin above. > Let the job be parameterless (or at least without these parameters), and determine day of week in the build script and adapt behavior there. Actually, for the use case that led me here, that wouldn't seem doable: in our situation, people who are going to specify those values aren't developers/very technical. It's far easier to ask them to specify cron + param=value form than to twiddle with shell-scripting. So I'd personnally like to consider this plugin get forked.

          Daniel Beck added a comment -

          I have nothing against a plugin, but jwmach1 argued for making this a core feature. If James can commit to maintaining it, I see no problem in forking it into jenkinsci and releasing it into the Jenkins community update site.

          Daniel Beck added a comment - I have nothing against a plugin, but jwmach1 argued for making this a core feature. If James can commit to maintaining it, I see no problem in forking it into jenkinsci and releasing it into the Jenkins community update site.

          James Wilson added a comment -

          It's been a while. The best I can remember about plugin vs core for this functionality was centered around how hard it was to create the plugin. I think it felt a bit out-of-phase as a plugin. I completely understand the hesitance to add something like this to core as it would have a relatively small audience of users.

          That being said, I should have taken the final step to register the plugin with Jenkins so others can discover it easier. Maybe it has a larger audience than I think.

          James Wilson added a comment - It's been a while. The best I can remember about plugin vs core for this functionality was centered around how hard it was to create the plugin. I think it felt a bit out-of-phase as a plugin. I completely understand the hesitance to add something like this to core as it would have a relatively small audience of users. That being said, I should have taken the final step to register the plugin with Jenkins so others can discover it easier. Maybe it has a larger audience than I think.

          Baptiste Mathus added a comment - - edited

          Still double-checking, but as I said we have a use-case for it here. So I'm planning to be a maintainer if I fork it.
          And no problem James, we all have projects and prototypes we didn't finish , that's [hacker] life after all .

          Cheers

          Baptiste Mathus added a comment - - edited Still double-checking, but as I said we have a use-case for it here. So I'm planning to be a maintainer if I fork it. And no problem James, we all have projects and prototypes we didn't finish , that's [hacker] life after all . Cheers

          Andrew Gray added a comment - - edited

          +1..

          I have exactly this use-case. Will try out the parameterized-scheduler-plugin in the meantime.

          Andrew Gray added a comment - - edited +1.. I have exactly this use-case. Will try out the parameterized-scheduler-plugin in the meantime.

          I have same problem,
          I am not able to pass parameters from Job A to Job B. Job A is Approval job which will be approved by manager.
          The second job has to pick the parameter and should wait for the scheduled production time and gets build.
          I am not sure about this parameterized scheduler plugin.
          I will give a try and let you guys know how it works.
          If you guys any alternative way please let me know.

          Thanks

          srikanth reddy added a comment - I have same problem, I am not able to pass parameters from Job A to Job B. Job A is Approval job which will be approved by manager. The second job has to pick the parameter and should wait for the scheduled production time and gets build. I am not sure about this parameterized scheduler plugin. I will give a try and let you guys know how it works. If you guys any alternative way please let me know. Thanks

          +1

          I have exactly this use-case. Will try out the parameterized-scheduler-plugin in the meantime.

          Paul Lanzerstorfer added a comment - +1 I have exactly this use-case. Will try out the parameterized-scheduler-plugin in the meantime.

          Harsh Parekh added a comment -

          +1

          I see this feature having a lot potential. Especially if we can extend Blue Ocean's UI. 

          Harsh Parekh added a comment - +1 I see this feature having a lot potential. Especially if we can extend Blue Ocean's UI. 

          Baptiste Mathus added a comment - Please see https://wiki.jenkins.io/display/JENKINS/Parameterized+Scheduler+Plugin

          Was this fixed and added to Jenkins core, or is the "fix" to go use the Parameterized Scheduler Plugin?

          I ask, because I found parameterizedCron documented over at https://jenkins.io/doc/pipeline/steps/workflow-multibranch/ for the "Pipeline: Multibranch" plugin. However, despite having the latest version of the plugin listed at https://plugins.jenkins.io/workflow-multibranch (2.17), Jenkins still tells me:
          java.lang.NoSuchMethodError: No such DSL method 'parameterizedCron' found among steps

          Cody Casterline added a comment - Was this fixed and added to Jenkins core, or is the "fix" to go use the Parameterized Scheduler Plugin? I ask, because I found parameterizedCron documented over at https://jenkins.io/doc/pipeline/steps/workflow-multibranch/  for the "Pipeline: Multibranch" plugin. However, despite having the latest version of the plugin listed at https://plugins.jenkins.io/workflow-multibranch  (2.17), Jenkins still tells me: java.lang.NoSuchMethodError: No such DSL method 'parameterizedCron' found among steps

          Daniel Beck added a comment -

          fcodyc Unfortunately the docs are structured by top-level element, in this case properties. Since that one allows you to specify any job properties, those will show up nested below it, no matter what plugin provides them.

          Daniel Beck added a comment - fcodyc Unfortunately the docs are structured by top-level element, in this case properties . Since that one allows you to specify any job properties, those will show up nested below it, no matter what plugin provides them.

          Bassam Khouri added a comment -

          "Parameterized Scheduler" plugin's helpdoc has the following

           

          Clicking on "this Jenkins issue" points to this ticket.  Clearly, the original author the "Parameterized Scheduler" plugin has idea to integrate the plugin into the core.   This ticket should be reopened, or the help test from the "Parameterized Schedule" plugin should be updated.

          Bassam Khouri added a comment - "Parameterized Scheduler" plugin's helpdoc has the following   Clicking on "this Jenkins issue" points to this ticket.  Clearly, the original author the "Parameterized Scheduler" plugin has idea to integrate the plugin into the core.   This ticket should be reopened, or the help test from the "Parameterized Schedule" plugin should be updated.

          Fatema Hasta added a comment - - edited

          batmat Are we still available to use job dsl support for Parameterized Schedular for the Job dsl v 1.76? I am not able to get this plugin working 

          Fatema Hasta added a comment - - edited batmat Are we still available to use job dsl support for Parameterized Schedular for the Job dsl v 1.76? I am not able to get this plugin working 

          In which version of Jenkins has this feature been added?

          Dominik Kaspar added a comment - In which version of Jenkins has this feature been added?

          This feature is accessible through the plugin:

          https://plugins.jenkins.io/parameterized-scheduler/

          Baptiste Mathus added a comment - This feature is accessible through the plugin: https://plugins.jenkins.io/parameterized-scheduler/

            batmat Baptiste Mathus
            flozzone Florin Hillebrand
            Votes:
            18 Vote for this issue
            Watchers:
            29 Start watching this issue

              Created:
              Updated:
              Resolved: