[JIRA] (JENKINS-42643) Conditional application of triggers in Declarative

6 views
Skip to first unread message

andrew.bayer@gmail.com (JIRA)

unread,
Mar 10, 2017, 1:04:03 PM3/10/17
to jenkinsc...@googlegroups.com
Andrew Bayer updated an issue
 
Jenkins / Bug JENKINS-42643
Conditional application of triggers in Declarative
Change By: Andrew Bayer
Summary: when/if doesn't work Conditional application of triggers in trigger Declarative
Add Comment Add Comment
 
This message was sent by Atlassian JIRA (v7.3.0#73011-sha1:3c73d0e)
Atlassian logo

docwhat@gerf.org (JIRA)

unread,
Mar 10, 2017, 5:37:03 PM3/10/17
to jenkinsc...@googlegroups.com
Christian Höltje commented on Bug JENKINS-42643
 
Re: Conditional application of triggers in Declarative

❤️

Maybe allow with to work anyplace? Or at least most places? e.g. the properties section (or options or whatever it is called) as well as inside a stage?

bruce.adams@acm.org (JIRA)

unread,
Mar 26, 2017, 6:02:01 AM3/26/17
to jenkinsc...@googlegroups.com

An approach that works and seems legible:

String cron_string = BRANCH_NAME == "master" ? "@hourly" : ""

pipeline {
  agent none
  triggers { cron(cron_string) }
  stages {
    // do something
  }
}

 

zachweg@hotmail.com (JIRA)

unread,
Mar 21, 2018, 11:31:02 PM3/21/18
to jenkinsc...@googlegroups.com
Zach Weg commented on Improvement JENKINS-42643

We could really use a way to conditionally trigger multibranchpipeline builds by branch name with declarative dsl. Łukasz Dudek's suggestion to use a "when" directive within the "trigger" block seems preferable. Any status update on this issue?

zachweg@hotmail.com (JIRA)

unread,
Mar 21, 2018, 11:32:03 PM3/21/18
to jenkinsc...@googlegroups.com
Zach Weg edited a comment on Improvement JENKINS-42643
We could really use a way to conditionally trigger scheduled multibranchpipeline builds by branch name with declarative dsl. [~ljbd]'s suggestion to use a "when" directive within the "trigger" block seems preferable. Any status update on this issue?

docwhat@gerf.org (JIRA)

unread,
Jun 25, 2018, 1:23:04 PM6/25/18
to jenkinsc...@googlegroups.com

This has been working for me:

  triggers {
    cron(env.BRANCH_NAME == 'master' ? '@daily' : '')
  }
This message was sent by Atlassian JIRA (v7.10.1#710002-sha1:6efc396)

sean.grider@gmail.com (JIRA)

unread,
Sep 7, 2018, 8:49:03 PM9/7/18
to jenkinsc...@googlegroups.com

I would also love to see a feature that allowed the triggers to also specify the parameters to triggered job.

 

pipeline {
  triggers {
     cron('0 0 * * *', params { BUILD=TRUE })
     cron('0 3 * * *', params { DEPLOY=TRUE})
  }
}

This would alleviate the dependency on external jobs scheduled to trigger this pipeline to get the parameters at different times.

This message was sent by Atlassian Jira (v7.11.2#711002-sha1:fdc329d)

kompastver@gmail.com (JIRA)

unread,
Dec 12, 2018, 7:13:03 AM12/12/18
to jenkinsc...@googlegroups.com

In our case, we'd like to be able to enable or disable githubPush trigger based on a flag from a variable.

Something like this:

pipeline {
    triggers {
        when {
            expression { enableTrigger = true }
        }
        githubPush()
    }

    stages {
    // do something
    }
}

The workaround for cron trigger does not applicable for githubPush and others.

igwe.kalu@live.com (JIRA)

unread,
Dec 20, 2018, 2:46:04 AM12/20/18
to jenkinsc...@googlegroups.com

These discussions are quite are useful and I can relate with many of the ideas/suggestions in my own use cases.

 

Andrew Bayer, is there any plan to start progressing this issue soon?

daniel.watrous@trinet.com (JIRA)

unread,
Jan 10, 2019, 9:17:03 PM1/10/19
to jenkinsc...@googlegroups.com

Sean Grider, I found https://plugins.jenkins.io/parameterized-scheduler while looking for this same feature.

My use case is a little different. I have a build that deploys software, but I want that software to get cleaned up some fixed number of hours after the last build. What I really want is to schedule a one time build, but I realized I might be able to use triggers for this. When the initial build runs, I dynamically generate the cron to run at a time that would be the number of hours later that I want. When the clean up build runs, I would set the cron trigger to an empty string, so it effectively on runs one time...

irc@webratz.de (JIRA)

unread,
Apr 3, 2019, 4:13:03 AM4/3/19
to jenkinsc...@googlegroups.com

tri@tridnguyen.com (JIRA)

unread,
May 29, 2019, 2:46:11 PM5/29/19
to jenkinsc...@googlegroups.com

I imagine the cron string could be set conditionally (only has a value on `master` branch, and  an empty string if not)? In the case that you call cron with an empty string, would it have any side effect?

 

tri@tridnguyen.com (JIRA)

unread,
Jun 12, 2019, 3:10:04 PM6/12/19
to jenkinsc...@googlegroups.com
Tri Nguyen edited a comment on Improvement JENKINS-42643
- I imagine the cron string could be set conditionally (only has a value on `master` branch, and  an empty string if not)? In the case that you call cron with an empty string, would it have any side effect? -

 
I tried this out, and while I can just set the cron job to an empty string, the problem is that I can't have an expression evaluated for the triggers. Here's how I tried it:


{code:java}
pipeline {
  triggers {
    cron( env.BRANCH_NAME.equals('master') ? '* 1 * * *' : '')
  }
} {code}

illakkiya123@gmail.com (JIRA)

unread,
Jul 18, 2019, 3:43:03 AM7/18/19
to jenkinsc...@googlegroups.com

It would be useful if we can have conditional triggers while using Parameterized cron trigger as well (https://github.com/jenkinsci/parameterized-scheduler-plugin)

Reply all
Reply to author
Forward
0 new messages