FuzzyAmi
FuzzyAmi

Reputation: 8137

How to use the 'parameterized-scheduler' plugin in Jenkins

I want to use the parameterized-scheduler plugin in Jenkins to run multiple jobs using cron that differ by a parameter. Sadly, the documentation is terrible. Can anyone guide me how to actually get it to work?

Upvotes: 3

Views: 7268

Answers (1)

FuzzyAmi
FuzzyAmi

Reputation: 8137

What this plugin does:

The parameterized-scheduler plugin can be used to define parameters that would be passed by cron into the env. Lets consider an example:

# pass `group1` into the group parameter when this job is run by cron
H 0 * * 0 % group=group1
# pass `group2` into the group parameter when this job is run by cron
H 0 * * 2 % group=group2

in the job itself, you can then print the value of the parameter:

# prints the value of group for this run
echo $group 

each time the job is run, the value of 'group' would be different, according to the cron spec above.

To actually get the above to work:

  1. you'll need to install the plugin (duh) and then,

  2. create a project with a group parameter. This is done in the 'General' section - select the 'This project is parameterized' checkbox and add a string parameter with some default value. We'll overwrite the value later in cron.

  3. save your project, and go back to 'configure'.

  4. a new checkbox should appear now in the Build Triggers section: "Build periodically with parameters". Select it and paste the following code:

    H 0 * * 0 % group=group1

    H 0 * * 2 % group=group2

the above code tells cron to run the task twice, once on Sunday and again on Tuesday, each time using a different value for the 'group' parameter.

Additional notes:

  1. do not run multiple tasks with the same crontab spec: make sure they run on different times, or else they wont run.
  2. if your tasks don't at all, try restarting jenkins.

Upvotes: 6

Related Questions