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

post/changed should make it easy to restrict on the new/previous status

    Details

    • Epic Link:
    • Similar Issues:

      Description

      post/changed is called for both X->SUCCESS, or SUCCESS->X.
      X being typically failure or unstable.

      As a user, I would like to have a very straightforward way to express that I'm only interested in the X->SUCCESS direction, because actually the SUCCESS->X is already covered by post/unstable or post/failure blocks.

      My use case is the following: I want to send an email for failures, unstable, and back to success. For the reason explained above, I don't want to send a notification when the status changes from success to something else, because then I would send two notifications instead for one actual event. And it would lower the signal/noise ratio.
      I think it could be fullfilled like:

      post {
          // we could also add previousState below, btw. But in that case it would 
          // force me to express all the possible previous statuses, which I don't 
          // care about here
          changed(newState: SUCCESS) {
              mail to: NOTIFICATION_TARGET, subject: "BACK TO SUCCESS! YAY!: .......
          }
          failure {
              mail to: NOTIFICATION_TARGET, subject: "FAILURE: .......
          }
          // ...
      }
      

      Thanks!

        Attachments

          Issue Links

            Activity

            Hide
            batmat Baptiste Mathus added a comment -

            Though I didn't try it yet, I suspect the current workaround would be:

            post {
                changed {
                    script {
                        if(currentBuild.result == "SUCCESS) { // pseudo-code, didn't check the exact syntax
                            mail to: NOTIFICATION_TARGET, subject: "BACK TO SUCCESS! : .......
                        }
                    }
                }
            }
            
            Show
            batmat Baptiste Mathus added a comment - Though I didn't try it yet, I suspect the current workaround would be: post { changed { script { if (currentBuild.result == "SUCCESS) { // pseudo-code, didn't check the exact syntax mail to: NOTIFICATION_TARGET, subject: "BACK TO SUCCESS! : ....... } } } }
            Hide
            batmat Baptiste Mathus added a comment -

            Just checked, and it's wee a bit more convoluted. As I forgot, currentBuild.result is only set on FAILURE, hence it is actually:

            post {
                changed {
                    script {
                        if (currentBuild.result == null) {
                            mail to: NOTIFICATION_TARGET, subject: "BACK TO SUCCESS: ${currentBuild.fullDisplayName}", body: "Yay! $BUILD_URL"
                        }
                    }
                }
            }
            
            Show
            batmat Baptiste Mathus added a comment - Just checked, and it's wee a bit more convoluted. As I forgot, currentBuild.result is only set on FAILURE, hence it is actually: post { changed { script { if (currentBuild.result == null ) { mail to: NOTIFICATION_TARGET, subject: "BACK TO SUCCESS: ${currentBuild.fullDisplayName}" , body: "Yay! $BUILD_URL" } } } }
            Hide
            abayer Andrew Bayer added a comment -

            PR up at https://github.com/jenkinsci/pipeline-model-definition-plugin/pull/248 to add new fixed and regression post conditions. Not as general purpose as what you originally proposed but a lot better fit with the syntax and parsing. =)

            Show
            abayer Andrew Bayer added a comment - PR up at https://github.com/jenkinsci/pipeline-model-definition-plugin/pull/248 to add new fixed and regression post conditions. Not as general purpose as what you originally proposed but a lot better fit with the syntax and parsing. =)
            Hide
            scm_issue_link SCM/JIRA link daemon added a comment -

            Code changed in jenkins
            User: Andrew Bayer
            Path:
            pipeline-model-definition/src/main/groovy/org/jenkinsci/plugins/pipeline/modeldefinition/model/conditions/Fixed.groovy
            pipeline-model-definition/src/main/groovy/org/jenkinsci/plugins/pipeline/modeldefinition/model/conditions/Regression.groovy
            pipeline-model-definition/src/main/resources/org/jenkinsci/plugins/pipeline/modeldefinition/model/conditions/Messages.properties
            pipeline-model-definition/src/test/java/org/jenkinsci/plugins/pipeline/modeldefinition/BuildConditionResponderTest.java
            pipeline-model-definition/src/test/resources/postOnChangeChanged.groovy
            pipeline-model-definition/src/test/resources/postOnChangeFailed.groovy
            http://jenkins-ci.org/commit/pipeline-model-definition-plugin/3f433c84f146589c0f10c9529243ac61ec508635
            Log:
            [FIXED JENKINS-41060] Add new fixed/regression post conditions

            Show
            scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Andrew Bayer Path: pipeline-model-definition/src/main/groovy/org/jenkinsci/plugins/pipeline/modeldefinition/model/conditions/Fixed.groovy pipeline-model-definition/src/main/groovy/org/jenkinsci/plugins/pipeline/modeldefinition/model/conditions/Regression.groovy pipeline-model-definition/src/main/resources/org/jenkinsci/plugins/pipeline/modeldefinition/model/conditions/Messages.properties pipeline-model-definition/src/test/java/org/jenkinsci/plugins/pipeline/modeldefinition/BuildConditionResponderTest.java pipeline-model-definition/src/test/resources/postOnChangeChanged.groovy pipeline-model-definition/src/test/resources/postOnChangeFailed.groovy http://jenkins-ci.org/commit/pipeline-model-definition-plugin/3f433c84f146589c0f10c9529243ac61ec508635 Log: [FIXED JENKINS-41060] Add new fixed/regression post conditions
            Hide
            abayer Andrew Bayer added a comment -

            This'll be in the upcoming Declarative 1.2.8.

            Show
            abayer Andrew Bayer added a comment - This'll be in the upcoming Declarative 1.2.8.
            Hide
            batmat Baptiste Mathus added a comment -

            Wooot. Thanks Andrew!

            Show
            batmat Baptiste Mathus added a comment - Wooot. Thanks Andrew!

              People

              • Assignee:
                abayer Andrew Bayer
                Reporter:
                batmat Baptiste Mathus
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: