techjourneyman
techjourneyman

Reputation: 1813

Jenkins multiple cron triggers with different build parameters

I am using a parameterized cron in my Jenkins script to run with 2 different sets of build param - one would run every 5 mins in production, and every 15 minutes in staging. The production one is running every 5 mins, but the staging one is not running. Can someone please tell me what I might be missing?

properties([
    pipelineTriggers([parameterizedCron(env.BRANCH_NAME != 'master' ? '''                                                                         
                                                                        H/5 * * * * % environment=production
                                                                        H/15 * * * * % environment=staging''' : '')]),
    parameters([
        choice(name: 'environment', defaultValue: 'sandbox', choices: ['sandbox', 'staging', 'production'], description: "etc")
    ])
])

A made a slight modification as follows and surprisingly this time only the staging one is running

properties([
    pipelineTriggers([parameterizedCron('''H/2 * * * * % environment=production'''), parameterizedCron('''H/4 * * * * % environment=staging''')]),
    parameters([
        choice(name: 'environment', defaultValue: 'sandbox', choices: ['sandbox', 'staging', 'production'], description: "etc")
    ])
])

I can't find the reason why either is working half-way only.

Can someone please tell me what can be changed to fix the issue?

Upvotes: 2

Views: 3498

Answers (2)

MaratC
MaratC

Reputation: 6859

It's possible that H/5 schedule overwrites the H/15 schedule because there is a conflict between them, so it's unclear what parameters should be used e.g. at 15th minute. (You probably want two runs with different parameters, but not clear if the plugin understands that.)

You can try specifying that exactly:

    pipelineTriggers([parameterizedCron(env.BRANCH_NAME != 'master' ? '''                                                                         
       0,5,10,15,20,25,30,35,40,45,50,55 * * * * % environment=production
       0,15,30,45 * * * * % environment=staging''' : '')]),

Upvotes: 3

techjourneyman
techjourneyman

Reputation: 1813

Looks like there is a known bug that's open https://issues.jenkins-ci.org/browse/JENKINS-49921. It's possible to space out the runs as suggested in the bug itself as a workaround.

This worked for me

pipelineTriggers([parameterizedCron('''
                                                                        # Every 10 mins in production
                                                                        */10 * * * * %environment=production
                                                                        # Every 22 minutes in staging
                                                                        */22 * * * * %environment=staging
                                                                    ''' : '')])

Upvotes: 1

Related Questions