Prevent Email Trigger Using Groovy Script

Article ID:115001097647
1 minute readKnowledge base

Issue

You need to prevent emails from being sent based on specific output in a build’s console output.

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.

References