Build and send mail using jenkins

table of Contents

One, system configuration

Two, connect to build nodes

Three, create and configure Item

Fourth, the problems encountered


One, system configuration

To build and send emails using jenkins, you first need to configure it globally.

1. Enter the jenkins overview interface -> click Manage Jenkins -> click Configure System to enter the configuration interface;

2. Configure Extended E-mail Notification;

◎ SMTP server fill in the SMTP server;

◎ Default user E-mail suffix fill in the default email suffix;

◎ Check the Use SMTP Authentication option;

◎ User Name/Password Fill in the email address and password. If the Project From in step 5 of Chapter 3 is blank, the default email address is this; if you want to set up multiple email addresses, you can click the Add button below, here I am Just fill in 2;

◎ The SMTP port I filled in is 25, this is based on the actual situation;

◎ Fill in UTF-8 for Charset;

The next step is to configure the default mail body. This part of the content can be configured according to actual needs. The following is a reference;

◎ Default Content Type is the default message body type;

◎ Default Recipients is the default recipient;

◎ Reply To List is the default reply list;

◎ Default Subject is the default mail name;

◎ Default Content is the default message body;

Next, check Enable Debug Mode, Enable watching for jobs, Default Triggers can be configured according to actual needs, these are for the convenience of debugging;

3. Configure E-mail Notification;

This is similar to the content of Step 2, so let's refer to it;

4. Click save to save, and the global configuration is OK.

 

Two, connect to build nodes

1. Because my build node is a Linux system, I first need to install SSH-related plug-ins on jenkins. Find Manage jenkins->Manage Plugins->SSH Build Agents and click install;

2. Next, create a jenkins node, find the New Nodes button, click it, and enter the Node Name you want;

3. After clicking OK, come to the configuration interface, pay attention to the Launch method here, select Launch agents via SSH, and fill in the IP, username and password for Host and Credentials respectively. Finally click save to save;

 

Three, create and configure Item

1. Next to the home page, click the New Item button under the View you want to create an Item;

2. Enter the name of the item you want, you can choose to copy the configuration of other items, click OK and the creation is successful;

3. Of course, after copying other items, we need to adjust the current item;

4. First write any description information you want to write in the Description, check Restrict where this project can be run, and enter the node name we created in the first step;

5. Configure Build periodically in Build Triggers, which is the time of automatic triggering. For example, I configured to trigger the build at 5 PM every Friday;

6. Add a build step. For example, if I want to run a py file under Linux, I need to select Execute shell, and then write the command I want to run;

7. Add post-build steps. Here I configure the function of sending emails after each build. First, select the Editable Email Notification function in Add post-build action. You can write or not write in the Project From column. The default system administrator’s mailbox has sent emails;

8. Click Advanced Settings in the lower right corner of the figure above:

◎ For the Triggers section, I chose Always, which means that emails will be sent regardless of whether the build succeeds or fails;

◎ Recipient List is the recipient list, just write the email account, multiple email accounts are separated by commas;

◎ Select HTML for Content Type, so the following Content uses HTML format;

◎ Subject is the name of the email;

◎ Attachments are email attachments. I will send the MyItem.xls file in the build directory of the build node as email attachments. Multiple attachments are separated by commas;

◎ Attach Build Log is whether to add the build log in the attachment, I choose yes;

9. After saving, you can wait for it to build on time.

 

Fourth, the problems encountered

After the initial build, the steps of sending emails always report this error: 535 5.7.3 Authentication unsuccessful, the reason for the error searched:

1. The email address is incomplete or the password is wrong;

2. SMTP information configuration error;

I checked these and no problem. Finally, it was found out that the format of the email body was incorrect. After modifying the format, building + sending the email was completed in one go.

 

 

 

Guess you like

Origin blog.csdn.net/wxt_hillwill/article/details/112024306