8
votes

In a Jenkins job config's Build Triggers section, it is possible to add multiple cron expressions separated on each line in the Schedule textarea e.g:

13 20 * * 0,1,2,3,4,5,6
13 8 * * 0,1,2,3,4,5,6

https://stackoverflow.com/a/44209349/1291886

How would one do this using the job-dsl/pipeline syntax?

3

3 Answers

13
votes

Using the job-dsl syntax:

triggers {
    cron('13 20 * * 0,1,2,3,4,5,6 \n 13 8 * * 0,1,2,3,4,5,6')
}

From the job-dsl documentation:

To configure a multi-line entry, use a single trigger string with entries separated by \n.

https://jenkinsci.github.io/job-dsl-plugin/#path/freeStyleJob-triggers-cron

4
votes

I recommend changing the lines 13 20 * * 0,1,2,3,4,5,6 to 13 20 * * 0-6, beauty in the details.

1
votes

As cron support string parameter, try this with string operation concat with next line (\n):

cron('41 12 20 10 *' + '\n 41 12 5 11 *' + '\n 41 12 15 11 *')