• jenkins--邮件插件配置


    需求:开发 merge或提交代码后 ,jenkins 构建失败,jenkins 自带邮件通知功能不能满足发给指定人员的需求,如谁 merge 的就发送给谁,想发送给该项目组所有成员等

    解决方案:安装Email Extension Plugin插件

    安装方法:jenkins --> Manage Jenkins --> Manage Plugins

    配置位置:jenkins --> Configure System --> Extended E-mail Notification

    配置描述:

    1) Default Content Type

             默认的邮件内容格式,文本类型或HTML类型

    (2)Default Recipients

            设置默认的邮件接收人,设置后就可以在任务的配置中使用$DEFAULT_RECIPIENT来直接发送邮件,非常方便

            具体的格式抄送用“cc:”前缀,密送用“bcc:”前缀,不使用前缀默认为收件人

            多个接收人,用逗号分割,譬如cc:someone@example.com, bcc:bob@example.com

    (3)Default Subject

            默认的邮件主题,$BUILD_NUMBER , $BUILD_STATUS!构建的编号和构建的状态,具体可以超看界面下方的“Content Token Reference”帮助,里面列出了所有的变量

    (4)Default Content

           默认内容,这步可以省略,具体可以到任务的配置中去设置,还会介绍到模版

    (5)Default Triggers

          默认的邮件触发器,就是什么情况下触发邮件的发送,这里只设置了在构建失败和成功时发送邮件

     

    这里着重讲 Default Content :

    •     这里涉及到了模版,在解释${JELLY_SCRIPT,template="custom"}这段是什么意思之前,我们先进入Jenkins目录里看一看
    •         进入Jenkins安装目录pluginsemail-extWEB-INFlib目录下,解压unzip email-ext.jar后进入hudsonpluginsemailext emplates目录下, 你会发现有一些template文件,这些就是插件自带的邮件模板,支持Jelly和Groovy的扩展。在对应上面的语法,template="custom" custom就是模版的文件名称,作者试了一圈下来选的是html-with-health-and-console.jelly,因为这个模版支持同步控制台输出日志,这个功能可帮开发定位错误。
    •   作者jenkins 的 home 目录为/usr/local/tomcat-9.0.20/webapps/jenkins   在这个目录下新建一个文件夹为email-templates,将html-with-health-and-console.jelly模版文件复制一份到这个目录下,改名为 custom.jelly,我们也可以打开这个模版文件,看看里面的语法是怎样的,然后找找资料自己写一个,或者拷贝出来改一改符合自己的需求,作为自定义模版来使用
    •       如何看模版符合你的需求,还有一个更快速的预览功能,从jenkings主界面进入你的任务,看左侧面板“Email Template Testing”(看下图1),模版文件如果以“.jelly”结尾就输入不带后缀的部分,如果以".template"结尾就输入全称(图2)

           

    • 从下图报错区域可看出,这个 Groovy 文件读取的地址为${JENKINS_HOME}/email-templates(图2),图3为实际结果
    • 设置好之后系统配置 Default Content 部分配置成${JELLY_SCRIPT,template="custom"}即可

    配置完成后构建任务操作:

    • 进入配置:增加构建后操作步骤-->Ediable Email Notification(图4):除了高级设置中的邮件触发类型 Triggers 外,其它都可以使用系统默认的,如另有需求,可Disable Extended Email Publisher
    • Send to Recipient List(邮件发送给全局邮件列表配置的所有邮件地址) - Check this checkbox if you would like to have the email sent to the "Global Recipient List" configured above.
    • Send to Developers(发送给开发,谁check in就发送给谁) - Check this checkbox to send the email to anyone whochecked in code for the last build.  The plugin willgenerate an email address based on the committer's id and an appended "default email suffix" from Jenkins's global configuration page.  For instance, if a change was committed by someone with an id "first.last", and the default email suffix is "@somewhere.com", then an email will be sent to first.last@somewhere.com
    • Include Culprits(发送给所有提交代码的人,直到最后build成功) - If this is checked AND Send To Developers is checked, emails will include everyone who committed since the last successful build.
    • Recipient List(邮件接收者) - A comma(逗号) (and whitespace) separated list of email address that should receive this email if it is triggered.  This list is appended to the "Global Recipient List" above.
    • Suspects causing the build to begin failing (导致构建失败的人)
    • Requestor(请求者)
    • Suspects causing unit tests to begin failing(导致单元测试失败的人)
    • Upstream Committers(上游提交者)

    图1:

    图2:

    图4:

    三十六般武艺,七十二般变化,修练出个人品牌并发出光芒
  • 相关阅读:
    2005226考勤登记
    2005219考勤登记
    2005225考勤登记
    2005224考勤登记
    2005222考勤登记
    116道iOS面试题+答案,希望对你的面试有帮助
    在线代码编辑器(Ace)被防火墙误杀
    使用Certbot实现阿里云泛域名证书的自动续期
    实时音视频入门学习:开源工程WebRTC的技术原理和使用浅析
    百善孝为先
  • 原文地址:https://www.cnblogs.com/deeptester-vv/p/13441804.html
Copyright © 2020-2023  润新知