To answer my own question:
#!/usr/bin/env groovy
def schedule = env.BRANCH_NAME.contains('master') ? '@weekly' : env.BRANCH_NAME
== 'develop' ? '@midnight' : ''
pipeline {
triggers {
cron(schedule)
}
Worked for me.
On Tuesday, July 9, 2019 at 10:34:06 AM UTC+2, Amedee Van Gasse wrote:
>
> 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).
>
--
You received this message because you are subscribed to the Google Groups
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/jenkinsci-users/ed96d9c4-e549-41d7-bd5a-2372a1ecfc22%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.