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

Pipeline post action should support conditions

XMLWordPrintable

    • Icon: Improvement Improvement
    • Resolution: Duplicate
    • Icon: Minor Minor
    • None
    • Jenkins ver. 2.138.2
      Pipeline: Model API 1.3.2

      Hello,

      Would be nice to add a when conditions to pipeline post actions. Here is an example:

      pipeline {
          agent any;
          stages { ... }
          // run only for master branch
          post {
              when { branch 'master' }
              failure {
                  // send slack notification about failure build
              }
          }
          // run without any additional conditions (it works now)
          post {
              success { ... }
              cleanup { ... }
          }
      }
      

      I don't have a good idea how to implement this without breaking-changes. In this example
      there is an idea that we can add multiple pipeline post blocks (one for every when condition)

      Motivation:
      I would like to send notification about failed builds, but only for releases braches. We don't want to receive notifications about failed pull requests builds.

            abayer Andrew Bayer
            y3ti Kamil Grabowski
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: