Is multiple triggers an option?

267 views
Skip to first unread message

Rusty Sapper

unread,
Feb 25, 2022, 11:42:58 AM2/25/22
to jenkins...@googlegroups.com
We have a huge pipeline that is currently set with a webhook trigger defined in a pipelineTriggers section in the properties section.  However, sometimes we would like some of these jobs to ONLY run nightly CI builds.  I'm trying to avoid having a second version of this huge pipeline script where the only difference is the piplineTrigger section.
    In a perfect world I'd have a Boolean parm for CI that when checked, the job used a cron type trigger and when unchecked, it used the web hook trigger... but I have seen anything like that.

any help would be appreciated.

Thanks,

Rusty

Gianluca

unread,
Feb 25, 2022, 11:57:40 AM2/25/22
to Jenkins Users

Hi,

We have the same requirements and we have a big pipeline that runs different things depending of the trigger and we have nightly CI builds.

 

We use the conditional “when” to identify the trigger and run some portion of the pipeline depending of where it comes from:

 

stage('Deploys') {
    when {
        beforeAgent true
        anyOf {
            triggeredBy 'UpstreamCause'
            triggeredBy 'BuildUpstreamCause'
            triggeredBy 'UserIdCause'
        }
    }

 

The above is a portion of the pipeline we only want to build when triggered by an upstream job or someone manually run it.

This exclude all webhooks related to push code to our repository, just to mention one.

 

stage('Setup') {
    when {
        beforeAgent true
        anyOf {
            triggeredBy 'GitHubPullRequestCommentCause'
        }
    }

 

The above is a part of the pipeline we want to run only when someone commented on GitHub and not on other webhooks.

 

And finally:

 

triggers {
    cron(branch.isMaster() ? 'H 0 * * *' : '')
}

 

We use the triggers option to setup nightly builds for the master branch only.

 

Hope that this is what you are looking for,

Cheers,

Gianluca.

Reply all
Reply to author
Forward
0 new messages