11

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?

halfer
  • 19,824
  • 17
  • 99
  • 186
edst
  • 1,074
  • 10
  • 20

3 Answers3

17

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

edst
  • 1,074
  • 10
  • 20
5

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

Obsidian
  • 3,719
  • 8
  • 17
  • 30
1

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 *')
Roberto Caboni
  • 7,252
  • 10
  • 25
  • 39