I have a *declarative* Jenkinsfile.
I want to have a daily build of the develop branch.
I currently have the following trigger:
triggers {
cron(env.BRANCH_NAME == 'develop' ? '@midnight' : '')
}
Now I also want to build the master branch. Not daily, but weekly.
I already know that I can have only one cron expression in triggers.
I know of one solution that works, and that I do not want to use: have a different cron expression committed to each branch.
I don't want that, because master branches from develop and then gets merged back into develop. Doing it that way, will cause merge conflicts that I don't want to deal with.
The other solution is to have a more complex cron expression in the trigger.
In pseudo code:
IF (env.BRANCH_NAME = 'develop')
THEN cron = '@midnight'
ELSE IF (env.BRANCH_NAME = 'master')
THEN cron = '@weekly'
I don't know how to construct the correct syntax for the cron expression. Is that Groovy? Linux shell? Something else?
If possible, then I would like to avoid "polluting" my declarative pipeline with script blocks (I don't even know if they are allowed inside triggers).