[jenkins] pipeline send email

Configuring general email notifications: System Administration - System Configuration
insert image description here

Configure regular email notifications

insert image description here

stage("send mail test") {
    
    
	steps{
    
    
	    script {
    
    
	        mail to: '[email protected]',
	        cc: '[email protected]',  // 抄送
	        charset:'UTF-8', // or GBK/GB18030
	        mimeType:'text/plain', // or text/html
	        subject: "Test_${
      
      env.JOB_NAME} - Build #${
      
      env.BUILD_NUMBER}",
	        body: "测试报告: ${
      
      env.BUILD_URL}/allure"
	    }
	}
}

Use mailbox extensions

Plug-in market download: Extended E-mail Notification

insert image description here

post {
    
    
    always {
    
    
        emailext (
            subject: "Build: Job '${
      
      env.JOB_NAME} [${
      
      env.BUILD_NUMBER}]'",
            body: '''<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body leftmargin="8" marginwidth="0" topmargin="8" marginheight="4" offset="0">
    <table width="95%" cellpadding="20" cellspacing="0" style="font-size: 1pt; font-family: Tahoma, Arial, Helvetica, sans-serif">
        <tr>
            <td><br />
                <b><font color="#0B610B"><font size="6">构建信息</font></font></b>
                <hr size="2" width="100%" align="center" /></td>
        </tr>
        <tr>
            <td>
                <ul>
                <div style="font-size:15px">
                    <li>构建项目:${PROJECT_NAME}</li>
                    <li>构建结果:<span style="color:red">${BUILD_STATUS} </span></li>
                    <li>构建编号:${BUILD_NUMBER}</li>
                    <li>触发用户:${CAUSE}</li>
                    <li>变更概要:${CHANGES}</li>
                    <li>构建地址:<a href=${BUILD_URL}>${BUILD_URL}</a></li>
                    <li>构建日志:<a href=${BUILD_URL}console>${BUILD_URL}console</a></li>
                    <li>报告地址:<a href=${BUILD_URL}allure>${BUILD_URL}allure</a></li>
                    <li>变更集:${JELLY_SCRIPT}</li>
                </div>
                </ul>
            </td>
        </tr>
    </table></font>
</body>
</html>''',
            to: "[email protected]",
            from: "[email protected]"
        )
    }
}

Guess you like

Origin blog.csdn.net/lan_yangbi/article/details/129127696