5

Whenever a certain condition holds true in the Execute shell of a Post-build step for a successful build, I want to trigger an email send. The problem is that, even when the condition doesn't hold true, the build is considered a success.

What I'm trying to implement:

if [condition == true]; then
  <do some action1>
  exit 0; //This success code should trigger email
else
  <do different action2>
  exit 0; //This success code should not trigger email
fi

The exit codes are 0 as both of the actions above are valid and it's a successful build. How do I send an email on success based on some criteria in Jenkins?

Sabuncu
  • 5,095
  • 5
  • 55
  • 89
Naresh
  • 51
  • 1
  • 2

1 Answers1

6

You should be able to build this using the Email-ext plugin. It will allow you to create custom triggers and specify the content of the email.

Addition: Use a 'Script - After Build' trigger from the plugin that checks on an environment variable that you set in your post build script to determine if the mail should be sent or not. Possibly you will need to move your post-build script to the build itself if the 'After Build' trigger is evaluated before other post-build scripts.

Simon Groenewolt
  • 10,607
  • 1
  • 36
  • 64
  • I'm already using the Email-ext plugin. It has trigger for SUCCESS. But i want to trigger mail based a condition for SUCCESSful build. (i.e) not for all SUCCESS builds. – Naresh Jun 26 '14 at 14:29
  • Is this problem solved. I have the same requirement. ? – Mohit Arora Jun 01 '16 at 12:25
  • 1
    I use **Post-build Actions** > **Editable Email Notification**, here it has "Pre-send Script" (need to click "Advanced..." to see it) - I usually put my conditions to it (set `cancel` to true to abort email sending, e.g.: `if (resFile.length() == 0) cancel = true` - this will prevent message from sending if file is zero-length, of course I have a few lines before to define `resFile` variable...) – RAM237 Jul 05 '17 at 15:15