I am looking to implement different cron triggers per branch in a declarative pipeline jenkins job. At the minute, I am only triggering hourly builds on our dev branch:
String cron_string = BRANCH_NAME == "dev" ? "@hourly" : ""
pipeline {
triggers {
cron(cron_string)
}
//stages, options and more code here...
}
My aim would be to have two separate cron strings that would trigger builds at different times in separate branches (eg: hourly builds in dev, every three hours builds in master), however the execution would be identical. My question is, can I do something like the code block below or should I take a different approach?
String cron_string_1 = BRANCH_NAME == "dev" ? "0 8/20 ? * MON-FRY" : ""
String cron_string_2 = BRANCH_NAME == "master" ? "0 8/20/3 ? * MON-FRY" : ""
pipeline {
triggers {
cron(cron_string)
}
//stages, options and more code here...
}