詹金斯:基于每个构建步骤发送电子邮件导致相同的詹金斯作业 [英] Jenkins: Sending email based on each build step result in same Jenkins Job

查看:187
本文介绍了詹金斯:基于每个构建步骤发送电子邮件导致相同的詹金斯作业的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想知道如何发送电子邮件与电子邮件基于每个构建步骤的插件相同的Jenkins Job。这是我的场景

I am just wondering how to send out email with Email-ext plugin based on each build step result on same Jenkins Job. Here is my scenario

我的Jenkins工作有3个构建步骤

My Jenkins job has 3 Build steps

Build Step1:

Build Step1:

   Pull latest code from github and Build the app - Gradle task which build the Jar

构建步骤2:

   Run all Tests against that Jar - Gradle Task which runs all Junit tests and provide Report files.

Post Build Action:

Post Build Action:

   If Build step1 fails -> Send email telling Build fails and Console Log with Exception detials

   If Build success and Tests run -> Send email with Test Reports

我想我需要写预发送脚本为电子邮件扩展插件。但我不知道如何写这个脚本。请协助。

I think i would need to write Pre-send script for Email-Ext plugin. But i am not sure how to write this script. Please assist.

推荐答案

在正常配置中,如果Build步骤1失败,Build Step 2将不会执行。

In a normal configuration, if Build Step 1 fails, Build Step 2 will not execute anyways.

如果构建步骤2(测试)失败,构建将被标记为不稳定,而不是失败。

And if Build Step 2 (Test) fail, the build will be marked "Unstable", not "Failed".

Email-ext 已经支持这些触发器。

Email-ext already supports triggers for these.


  • 滚动到您的可编辑电子邮件通知部分。

  • 点击 高级设置... 按钮。

  • 查看触发器部分。

  • 点击 添加触发器 按钮。

  • Scroll to your Editable Email Notification section.
  • Click Advanced Settings... button.
  • Look under Triggers section.
  • Click Add Trigger button.

失败的触发器和不稳定的触发器(您也可能需要成功的触发器)

You want to configure a trigger for "Failure" and a trigger for "Unstable" (you will also probably want a trigger for "Success")

在失败触发器中,在构建失败时写入所需的电子邮件内容(构建步骤1失败将导致此错误)。

In您的不稳定触发器,在测试用例失败时写入您想要的电子邮件内容。

在您的成功触发器中,写入您想要的电子邮件内容,一切顺利,您要发送测试报告。

In your "Failure" trigger, write the email content you want for when the build fails (Build Step 1 failure will cause this for you).
In your "Unstable" trigger, write the email content you want for when the test cases fail.
In your "Success" trigger, write the email content you want for when everything was successful and you want to send the test report.

替代方法:

或者您可以查看任何构建步骤 插件(这应该允许后期制作操作,如电子邮件 - ext,作为构建步骤执行), 条件构建步骤 插件(允许为每个构建步骤创建条件)。组合两者并创建条件,当您要触发电子邮件扩展构建步骤。但是我没有尝试过,也不能保证这样做。

Alternative:
Or you can look into Any Build Step plugin (which should allow post-build actions, like email-ext, to be executed as a build step), and Conditional Build Step plugin (which allows to create conditions for each build step). Combine the two and create conditions when you want to trigger the email-ext build step. However I have not tried this and can't guarantee this will work.

这篇关于詹金斯:基于每个构建步骤发送电子邮件导致相同的詹金斯作业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆