Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-42643

Conditional application of triggers in Declarative

    Details

    • Similar Issues:

      Description

      I want to be able to use trigger with cron but only for the master branch.

      if and when both don't work in the trigger context.

      Here is what I expected to work:

       

      if (env.BRANCH == 'master') {
        trigger { cron('@daily') }
      }
      

        Attachments

          Issue Links

            Activity

            Hide
            igwe Igwe Kalu added a comment -

            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?

            Show
            igwe Igwe Kalu added a comment - 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?
            Hide
            dwatroustrinet Daniel Watrous added a comment -

            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...

            Show
            dwatroustrinet Daniel Watrous added a comment - 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...
            Hide
            webrat Andreas Sieferlinger added a comment -

            Has there been any progress on this?

            Show
            webrat Andreas Sieferlinger added a comment - Has there been any progress on this?
            Hide
            tridnguyen Tri Nguyen added a comment - - edited

            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:

            pipeline {
              triggers {
                cron( env.BRANCH_NAME.equals('master') ? '* 1 * * *' : '')
              }
            } 
            Show
            tridnguyen Tri Nguyen added a comment - - edited 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: pipeline { triggers { cron( env.BRANCH_NAME.equals( 'master' ) ? '* 1 * * *' : '') } }
            Hide
            tulip Illakkiya Ravichandran added a comment -

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

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

              People

              • Assignee:
                abayer Andrew Bayer
                Reporter:
                docwhat Christian Höltje
              • Votes:
                41 Vote for this issue
                Watchers:
                50 Start watching this issue

                Dates

                • Created:
                  Updated: