「Jenkins Plugins」- 邮件通知 | Email Extension

虽然邮件通知较慢,但是我们依旧保留邮件通知方法,作为补充手段。

Pipeline Basic Steps / mail

官网:
文档:https://www.jenkins.io/doc/pipeline/steps/workflow-basic-steps/#mail-mail
仓库:

该功能为内置邮件发送功能,不需要安装额外的插件。

使用方法:
1)Manage Jenkins / Configure System / E-mail Notification

  • SMTP server: smtp.exmail.qq.com
  • Advanced
    • Use SMTP Authentication:
      • User Name: noreply@example.com
        • 需与 System Admin e-mail address 参数一致。否则,将提示 … 501 mail from address must be same as authorization user … 错误。
      • Password: xxxxxxx
    • Use SSL
    • SMTP Port: 465

2)在 Jenkins Pipeline 或 Freestyle Project 中,配置邮件发送即可。

在 Jenkins Pipeline 中,使用邮件通知的方法:

mail(
    to: "tony@example.com,mary@example.com,tom@example.com", // 收件人
    subject: "",     // 邮件标题
    body: ""         // 邮件内容
)

Email Extension | Email Extension Plugin

官网:https://plugins.jenkins.io/email-ext/
文档:https://www.jenkins.io/doc/pipeline/steps/email-ext
仓库:https://github.com/jenkinsci/email-ext-plugin

Pipeline Steps: emailext, emailextrecipients

在 Manage Jenkins / Configure System / Extended E-mail Notification 中,设置邮箱帐号信息;

Mailer | Mailer Plugin

官网:https://plugins.jenkins.io/mailer/
文档:https://www.jenkins.io/doc/pipeline/steps/mailer/
仓库:https://github.com/jenkinsci/mailer-plugin

Pipeline Steps: step([$class: ‘Mailer’])

在 Freestyle project 中,发送邮件给 Git 提交者

Passing variable from shell to email-ext in Jenkins – Stack Overflow
Token Macro | Jenkins plugin

技术关键词:Content Token Reference, Jenkins:3.1 Functions and Features:Token Macro

第一步、在 Build 中,执行如下脚本,创建 env.properties 配置:

rm -f ${WORKSPACE}/env.properties
touch ${WORKSPACE}/env.properties

GIT_COMMITER_EMAIL=$(git --no-pager show -s --format='%ae')
echo "git.committer=${GIT_COMMITER_EMAIL}" >> ${WORKSPACE}/env.properties

cat ${WORKSPACE}/env.properties

第二步、在 Editable Email Notification 中,设置 Project Recipient List 为:

${PROPFILE,file="env.properties",property="git.committer"}