jenkins configure the mail and enhanced version of the e-mail notification

Environmental
jenkins: 2.5 
Operating System: win7 
server: centos6 
Tools: CRT

Demand
this month that once jenkins automatic upgrade (SCM) fails, then just 19:00, until the next morning when someone clicks on, I realized that the upgrade fails, so think about it, I still build fails under configuration mail notification bar!

Plug
Email Extension Plugin

(Install plug-ins, I like to go hpi downloaded file, then go to manual installation)

jenkins default mail notification
let me explain, the default. 
jenkins there is a default e-mail notification, just too simple and can not be personalized or customized.

Setting the system administrator e-mail address


E-mail notification


①SMTP server: If you are using a company mail, then ask your own company's operation and maintenance personnel it; they generally know, at least I was asking the company's operation and maintenance personnel; if you intend to use QQ mailbox, then you need to under settings, online tutorials; NetEase mailbox enabled by default. 
Description: SMTP is a protocol 
② user default mail suffix: according to their own circumstances to set 
③ check use SMTP authentication, user name: according to its own settings, password too. 
④SMTP port: default 25

After configured, you can check the test, recipient enter your e-mail in Test e-mail, look at the success.

After successful, we can be configured in the job: 


After configured, the next test, I deliberately Here is wrong echo, it fails to build verification email.

Send e-mail results: 


It can be seen that the content of the message in plain text, not even a hyperlink, the content is rich enough!

Next, we use an enhanced version of the e-mail notification
system configuration
After installing the plug-in, your system is set up there will be such a setting:

Then the picture above: 


Click the Advanced button above: 


①SMTP server: before and empathy 
②Default user E-mail suffix: fill in according to their own circumstances 
③ Check the Use SMTP Authentication, user name and password to fill in their 
④SMTP port: default 25 
⑤Default Content Type: Mail Document type 
⑥Default Recipients: default recipient list , has divided the comma

Other I use the default or do not fill, click Save.

Note: 
the configuration above, all beginning with the name Default, can be used as variables in the job configuration. For example: the default recipient address: You can use this $ DEFAULT_RECIPIENTS in a separate job.

Individually configure a single job is
increased after the build procedure, adding enhanced mail notification (see portions circled in red): 


After you get:


Under a little explanation: 
①Disable Extended Email Publisher: When checked, the message is not sent, look at their own situation myself, if you want to debug something, do not want to send an email you can check this out. 
②Project Recipient List: recipient address; multiple recipients e-mail addresses separated by commas; want to use the global default configuration, you can use the $ DEFAULT_RECIPIENTS. 
③Project Reply-To List: allow the reply address of the person; To use the default system settings, you can use the $ DEFAULT_REPLYTO; 
④Content Type: type of mail document, you can set HTML and other formats; 
⑤Default Subject: default theme, that is the message title; Similarly you can use DEFAULT_SUBJECT $ 
⑥Default content: the default message content; here is the key; I used here is the template $ {SCRIPT, template = "groovy -html.template"}; later speaks; certainly do not want to use a template, then, You can use variables jenkins by itself provides its own definition; 
⑦Attach Build the log: contains log messages sent; 
several default like the following, the last Triggers critical; 
suppose the last one does not change, then, is not receiving the messages, this is a pit official leave, be sure to add yourself a Recipient List.

Click Save, click build, incoming mail in the following format: 


Problems encountered
problems a
An attempt to AN E-mail to the send empty List of Recipients, ignored.
1
this problem, I been stuck with for a long time, almost one day of it! Still do not know why not receive mail

Until Google to this place: 
https://stackoverflow.com/a/37167955/6952713

https://issues.jenkins-ci.org/browse/JENKINS-34731?focusedCommentId=257221&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-257221 
know, the official gave a pit .

Question two
Exception raised during template rendering: No signature of method: hudson.model.FreeStyleBuild.getExactRuns() is applicable for argument types: () values: [] Possible solutions: getActions(), getActions(java.lang.Class) groovy.lang.MissingMethodException: No signature of method: hudson.model.FreeStyleBuild.getExactRuns() is applicable for argument types: () values: [] Possible solutions: getActions(), getActions(java.lang.Class) at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:58) at org.codehaus.groovy.runtime.callsite.PojoMetaClassSite.call(PojoMetaClassSite.java:49) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117) at SimpleTemplateScript3.run(SimpleTemplateScript3.groovy:106) at groovy.text.SimpleTemplateEngine$SimpleTemplate$1.writeTo(SimpleTemplateEngine.java:168) at groovy.text.SimpleTemplateEngine$SimpleTemplate$1.toString(SimpleTemplateEngine.java:180) at hudson.plugins.emailext.plugins.content.ScriptContent.renderTemplate(ScriptContent.java:127) at hudson.plugins.emailext.plugins.content.ScriptContent.evaluate(ScriptContent.java:68) at hudson.plugins.emailext.plugins.content.AbstractEvalContent.evaluate(AbstractEvalContent.java:64) at org.jenkinsci.plugins.tokenmacro.DataBoundTokenMacro.evaluate(DataBoundTokenMacro.java:199) at 
1
This error is when I use e-mail templates, reported wrong! 
My steps are as follows: 
I refer to the official: https: //wiki.jenkins.io/display/JENKINS/Email-ext+plugin 
when Script content of this chapter content, download two Examples Template 
Jenkins-matrix- html.template-In Email 
Jenkins-Generic-Matrix-In Email-html.template

According to the official tutorial created jenkins home (/ home / jenkins / dataspace) directory of email-templates folder, and put the two templates to upload up, after Default Content in the job configuration is written:

SCRIPT {$, Template = "Jenkins-Matrix-In Email-html.template"}
. 1
Then constructed, it being given! 
It also bothers me a long time! Until Google to such a passage (really little information on the Internet);

http://jenkins-ci.361315.n4.nabble.com/Email-Template-Testing-Exception-td4807117.html

It reads as follows:

Looks like you are trying to test a matrix template with a non matrix job.

This means that:

It looks like you are in a non-matrix job in a test matrix template

Then went to inquire what is the matrix job; 
it is an official tutorial on matrix of 
Building a matrix project

See which content is to build a Multi-Configuration Projects; then a bit confused! Then see Matrix Project Plugin This plug-in; there's explain it reads:

Multi-configuration (matrix) project type.

It is almost certain matrix job is Multi-configuration project (project to build a multi-configuration). In other words I want to use jenkins-matrix-email-html.template this template you must create the corresponding job;

After testing, it really can, configurations are similar: the message results are as follows: 


Then the matrix job with this scene more than you? 
This is the official gives the experience:

Experience with Hudson - Building matrix project

To explain it:

For example, you want to test the project in jdk 1.4, 1.5,1.6 in, you can create this type of job;

Use a custom template
by problems encountered above, we sometimes want to define their own templates! 
Own templates There are two ways to use:

The method does not use a template
in the Default Content of this column, to write their own by Token: 
(token here, do not translate into a token, because they do not know what translated into, it will retain the original token)

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>${ENV, var="JOB_NAME"}-第${BUILD_NUMBER}次构建日志</title>
</head>

<body leftmargin="8" marginwidth="0" topmargin="8" marginheight="4"
    offset="0">
    <table width="95%" cellpadding="0" cellspacing="0"
        style="font-size: 11pt; font-family: Tahoma, Arial, Helvetica, sans-serif">
        <tr>
            <td>
                <h2>
                    <font>来自Mr.Jenkins的邮件通知</font>
                </h2>
            </td>
        </tr>
        <tr>
            <td>
                <br />
                <b><font color="#0B610B">构建信息</font></b>
               <hr size="2" width="100%" align="center" />
             </td>
        </tr>
        <tr>
            <td>
                <ul>
                    <li>项目名称&nbsp;:&nbsp;${PROJECT_NAME}</li>
                    <li>触发原因&nbsp;:${CAUSE}</li>
                    <li>构建日志&nbsp;:&nbsp;<a href="${BUILD_URL}console">${BUILD_URL}console</a></li>
                    <li>单元测试报告&nbsp;:<a href="${BUILD_URL}testReport/">${BUILD_URL}testReport/</a></li>
                    <li>工作目录&nbsp;:&nbsp;<a href="${PROJECT_URL}ws">${PROJECT_URL}ws</a></li>

                </ul>
            </td>
        </tr>
                <tr>
            <td><b><font color="#0B610B">构建日志:</font></b>
            <hr size="2" width="100%" align="center" /></td>
        </tr>
        <tr>
            <td><textarea cols="80" rows="30" readonly="readonly"
                    style="font-family: Courier New">${BUILD_LOG}</textarea>
            </td>
        </tr>
    </table>
</body>
</html>

Reproduced in: https: //my.oschina.net/u/4000302/blog/3053829

Guess you like

Origin blog.csdn.net/weixin_34220623/article/details/92424573