-
Improvement
-
Resolution: Unresolved
-
Minor
-
None
Problem:
If you want to only send out notifications in a post/failure block for non pull-requests, you have currently to use the script block.
Maybe a solution could be to allow when inside post/* (in the example below, having a way to express a default when would probably help make this more concise)
Example:
post { failure { script { if (env.CHANGE_ID == null) { mail to: NOTIFICATION_TARGET, subject: "FAILURE: ${currentBuild.fullDisplayName}", body: "Boo, we failed. $BUILD_URL" } } } unstable { script { if (env.CHANGE_ID == null) { mail to: NOTIFICATION_TARGET, subject: "UNSTABLE: ${currentBuild.fullDisplayName}", body: "Huh, we're unstable. $BUILD_URL" } } } changed { script { if (env.CHANGE_ID == null && currentBuild.result == null) { // and JENKINS-41060 mail to: NOTIFICATION_TARGET, subject: "BACK TO SUCCESS: ${currentBuild.fullDisplayName}", body: "Yay! $BUILD_URL" } } } }
Proposals (WARNING: do not copy paste below if you just found that JIRA
)
Expressing the when each time
post { failure { mail to: NOTIFICATION_TARGET, subject: "FAILURE: ${currentBuild.fullDisplayName}", body: "Boo, we failed. $BUILD_URL" when { expression { env.CHANGE_ID == null } } } unstable { mail to: NOTIFICATION_TARGET, subject: "UNSTABLE: ${currentBuild.fullDisplayName}", body: "Huh, we're unstable. $BUILD_URL" when { expression { env.CHANGE_ID == null } } } changed { mail to: NOTIFICATION_TARGET, subject: "BACK TO SUCCESS: ${currentBuild.fullDisplayName}", body: "Yay! $BUILD_URL" when { expression { env.CHANGE_ID == null && currentBuild.result == null } } } }
Expressing the when as a default for every post/* blocks
post { failure { mail to: NOTIFICATION_TARGET, subject: "FAILURE: ${currentBuild.fullDisplayName}", body: "Boo, we failed. $BUILD_URL" } unstable { mail to: NOTIFICATION_TARGET, subject: "UNSTABLE: ${currentBuild.fullDisplayName}", body: "Huh, we're unstable. $BUILD_URL" } changed { mail to: NOTIFICATION_TARGET, subject: "BACK TO SUCCESS: ${currentBuild.fullDisplayName}", body: "Yay! $BUILD_URL" when { expression { currentBuild.result == null } } // question arises then: should this expression be cumulative, or overriding the default below } when { expression { env.CHANGE_ID == null } } }
- is duplicated by
-
JENKINS-54602 Pipeline post action should support conditions
-
- Closed
-
- relates to
-
JENKINS-41060 post/changed should make it easy to restrict on the new/previous status
-
- Closed
-
-
JENKINS-40898 Declarative should provide an easy way to disable/enable some steps in an PR context or not
-
- Closed
-
you don't need env you simply put CHANGE_ID == null
Everything in post is already a conditional. Is there a chance putting the when outside of the existing conditions could cause conflicts?