首页 > 解决方案 > Jenkins:根据执行shell脚本条件发送邮件

问题描述

我在詹金斯有以下脚本

if diff file1.txt file2.txt > file3.txt ; then
  echo "no difference"
else
  <need to send email notitication>
fi

我听说我们可以使用“Email-ext 插件”来实现这一点,我的 Jenkins 中安装了插件。谁能解释一下如何使用Email-ext插件根据脚本条件发送邮件。

标签: jenkinsemail-extjenkins-email-ext

解决方案


您好,您可以参考链接了解配置电子邮件模板的详细步骤。在您的管道脚本中,您可以添加以下步骤以获取通知:

emailext body: ''
    '${SCRIPT, template="groovy-html.template"}'
    '', subject: "${env.JOB_NAME} - Build # ${env.BUILD_NUMBER} - Successful",
      mimeType: 'text/html', to: "email list"

groovy-html.template 是默认模板,您可以在电子邮件正文和主题中使用或编写自己的内容。


推荐阅读