How to trigger an email based on a specific condit

2019-08-10 12:21发布

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?

1条回答
劳资没心,怎么记你
2楼-- · 2019-08-10 12:46

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.

查看更多
登录 后发表回答