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

Provide means of detecting cause of build from declarative pipeline

    Details

    • Similar Issues:

      Description

      I'd like to be able to perform certain steps on my declartive pipeline when the build has been triggered via a nightly schedule, but not when it is triggered via SCM polling.

        Attachments

          Issue Links

            Activity

            Hide
            abayer Andrew Bayer added a comment -

            So what I'm thinking here is a when condition that checks the build cause? That'd let you conditionally execute stages based on the build cause...

            Show
            abayer Andrew Bayer added a comment - So what I'm thinking here is a when condition that checks the build cause? That'd let you conditionally execute stages based on the build cause...
            Hide
            keirlawson Keir Lawson added a comment -

            That makes sense.  Only issue is so far as I can see when clauses can't be used in combination with post, so if I want a notification to always fire regardless of previous steps failing, but only for certain build triggers, I can't do that.  Perhaps I should raise a seperate issue request when to be usable with post?

            Show
            keirlawson Keir Lawson added a comment - That makes sense.  Only issue is so far as I can see when clauses can't be used in combination with post , so if I want a notification to always fire regardless of previous steps failing, but only for certain build triggers, I can't do that.  Perhaps I should raise a seperate issue request when to be usable with post ?
            Hide
            jamesdumay James Dumay added a comment -

            Keep in mind that a run might have multiple causes.

            Show
            jamesdumay James Dumay added a comment - Keep in mind that a run might have multiple causes.
            Hide
            abayer Andrew Bayer added a comment -

            Feels like this could be done as a when condition utilizing https://github.com/jenkinsci/workflow-support-plugin/pull/78 - in post usage, you could do a script block and check the currentBuild.getBuildCauses() list for what you care about.

            Show
            abayer Andrew Bayer added a comment - Feels like this could be done as a when condition utilizing https://github.com/jenkinsci/workflow-support-plugin/pull/78 - in post usage, you could do a script block and check the currentBuild.getBuildCauses() list for what you care about.
            Hide
            jtaboada Jose Blas Camacho Taboada added a comment -

            This feature was implemented using run.getCauses() within a script in Utils.groovy

            Show
            jtaboada Jose Blas Camacho Taboada added a comment - This feature was implemented using run.getCauses() within a script in Utils.groovy
            Hide
            abayer Andrew Bayer added a comment -

            Merged, will be in 1.3.4.

            Show
            abayer Andrew Bayer added a comment - Merged, will be in 1.3.4.
            Hide
            ccaraivan Costin Caraivan added a comment -

            Andrew Bayer Is this documented somewhere? How do we use this? Thanks!

             

            Show
            ccaraivan Costin Caraivan added a comment - Andrew Bayer Is this documented somewhere? How do we use this? Thanks!  
            Hide
            jtaboada Jose Blas Camacho Taboada added a comment -

            Costin Caraivan, you can check the documentation here: https://jenkins.io/doc/book/pipeline/syntax/#declarative-pipeline

            And an example is: 

            when { triggeredBy 'SCMTrigger' }

            or TimerTrigger

            Show
            jtaboada Jose Blas Camacho Taboada added a comment - Costin Caraivan , you can check the documentation here: https://jenkins.io/doc/book/pipeline/syntax/#declarative-pipeline And an example is:  when { triggeredBy 'SCMTrigger' } or TimerTrigger

              People

              • Assignee:
                jtaboada Jose Blas Camacho Taboada
                Reporter:
                keirlawson Keir Lawson
              • Votes:
                2 Vote for this issue
                Watchers:
                8 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: