Issue
You need to prevent emails from being sent based on specific output in a build’s console output.
Environment
-
CloudBees CI (CloudBees Core) on modern cloud platforms - Managed controller
-
CloudBees CI (CloudBees Core) on traditional platforms - Client controller
-
CloudBees Jenkins Enterprise - Managed controller
Resolution
-
Click
Advanced Settings
in the Editable Email Notification section in a job’s configuration -
Remove the
Failue - Any
Trigger -
Add a new
Script - After Build
Trigger -
Add a groovy script that will only send an email if the build result is failure AND it meets your requirements.
-
The example groovy script below prevents emails when a string parameter is invalid via the Validating String Parameter Plugin.
Example groovy script
// only send an email if build ends in FAILURE AND the validating string parameter plugin phrase // is not found {{ERROR: Invalid value for parameter [version] specified:}} is NOT found in build // logs def invalidParameter invalidParameter = build.logFile.text.readLines().any{ it ==~ /.*Invalid value for parameter.*/} invalidParameter == false && build.result.toString().equals('FAILURE')
Please review the Triggers section on the email-ext plugin wiki page and the email-ext recipes wiki page for more examples.