cron trigger limited to one branch in the Jenkinsfile

1,449 views
Skip to first unread message

Francois Marot

unread,
Sep 10, 2021, 9:28:01 AM9/10/21
to Jenkins Users

Hello all,

I set up a cron trigger in my Jenkinsfile of the master branch, but now new branches are also built by this trigger at night. I would like to limit this behavior to my 'master' branch.
How would you do that ?
I know I can abort the build if I detect that that a cron triggered it but I dream of a simpler way.

pipeline {
    triggers {
        cron('H 5 * * 1,3,5')
    }
    ...

regards
François

Francois Marot

unread,
Mar 14, 2022, 4:44:52 AM3/14/22
to Jenkins Users
no one knows how to limit a cron to a branch in a Jenkinsfile ?

Mark Waite

unread,
Mar 14, 2022, 9:13:28 AM3/14/22
to Jenkins Users
On Monday, March 14, 2022 at 2:44:52 AM UTC-6  François wrote:
no one knows how to limit a cron to a branch in a Jenkinsfile ?


See https://github.com/jenkinsci/packaging/blob/5707f90ede196076fcd1308e517c90d52e0e9d99/Jenkinsfile#L6 for one technique to consider.  It makes the cron property conditional based on if the current branch is the primary branch in the repository.

Francois Marot

unread,
Apr 1, 2022, 3:45:26 AM4/1/22
to Jenkins Users
Thanks you mark,

sorry I hadn't seen your answer earlier. As another alternative, a colleague of mine found the "Parameterized Scheduler plugin" which is simple to use and does the job nicely as shown here: https://www.shellhacks.com/jenkins-schedule-build-periodically-parameters/
Have a good day !
Reply all
Reply to author
Forward
0 new messages