Jenkins configuring email notifications

Posted by supratwinturbo on Wed, 09 Mar 2022 13:12:37 +0100

After the continuous integration deployment based on jenkins is completed, the task construction is completed, and the test results need to be notified to relevant personnel. Here is how to configure email notification in jenkins.

1, Install mail plugin
System management - > management plug-in - > optional plug-in, select email extension plug-in for installation, and restart Jenkins after installation
I have installed the plug-in, so it is displayed in the installed directory here. For children's shoes that have not been installed, you can search for the plug-in through the search box in the upper right corner, and then install it online. After installation, restart Jenkins.

2, System settings
Configure the mail through system management → system settings:

1. Set jenkins address and administrator email address

2. Set sender and other information
PS: the sender's email address here should be consistent with the email address of the system administrator (of course, a special sender's email can also be set, but it does not affect the use. It can be set according to the specific situation)

Multiple people can be added to the default recipient mailbox in the figure above, separated by English half width commas.
3. Configure message content template

Attachment: email content template (Default Content):

<!DOCTYPE html>    
<meta charset="UTF-8">    
<title>${ENV, var="JOB_NAME"}-The first ${BUILD_NUMBER}Secondary build log</title>    
<body leftmargin="8" marginwidth="0" topmargin="8" marginheight="4"    
    <table width="95%" cellpadding="0" cellspacing="0"  style="font-size: 11pt; font-family: Tahoma, Arial, Helvetica, sans-serif">    
            This email is sent automatically by the system without reply!<br/>            
            Hello, colleagues, the following is ${PROJECT_NAME }Project construction information</br> 
            <td><font color="#CC0000 "> build result - ${build_status} < / font ></td>   
            <td><br />    
            <b><font color="#0b610b "> build information < / font ></b>    
            <hr size="2" width="100%" align="center" /></td>    
                    <li>Project Name: ${PROJECT_NAME}</li>    
                    <li>Build No.: page ${BUILD_NUMBER}Secondary construction</li>    
                    <li>Trigger reason: ${CAUSE}</li>    
                    <li>Build status: ${BUILD_STATUS}</li>    
                    <li>Build log: <a href="${BUILD_URL}console">${BUILD_URL}console</a></li>    
                    <li>structure  Url :  <a href="${BUILD_URL}">${BUILD_URL}</a></li>    
                    <li>Working directory: <a href="${PROJECT_URL}ws">${PROJECT_URL}ws</a></li>    
                    <li>project  Url :  <a href="${PROJECT_URL}">${PROJECT_URL}</a></li>    

<h4><font color="#0b610b "> failure case < / font > < / H4 >
<hr size="2" width="100%" />

<h4><font color="#0B610B">Recently submitted(#$SVN_REVISION)</font></h4>
<hr size="2" width="100%" />
${CHANGES_SINCE_LAST_SUCCESS, reverse=true, format="%c", changesFormat="<li>%d [%a] %m</li>"}
Detailed submission: <a href="${PROJECT_URL}changes">${PROJECT_URL}changes</a><br/>


4. Set email trigger mechanism

5. Configure the mail function of Jenkins
The configuration contents are as follows. The configuration is the same as that of the Email Extension Plugin. You can check the test configuration by sending test email button to test whether the configuration successfully sends email, as shown in the following figure:

3, Project configuration

After completing the system setting, you also need to configure the mail for the project to be built.

1. Enter the project configuration interface

Enter the new project interface, click the configuration button to enter the system configuration page:

2. Configure post build operation module
After entering the system configuration page, click the post build operation option above. The configuration contents are as follows:

You can configure the content by default. The mail content type can be selected according to your own configuration. The recipient list can be configured from the default recipient option in the previous system settings.
4, Build trigger mail test
The following figure shows the test email I received. The email content can be personalized through the system settings. You can refer to the template above or customize it.

Enable POP3/SMTP service for mailbox. Take QQ mailbox as an example
1. Log in to QQ email

2. Open "POP3/SMTP" in "account" and obtain the authorization code

3. After sending SMS verification, get the following verification code

The verification code is the password configured in Jenkins email settings.

Topics: Operation & Maintenance jenkins