
转载注明出处,欢迎关注微信小程序小白AI博客 微信公众号小白AI或者网站 https://xiaobaiai.net或者我的CSDN https://blog.csdn.net/freeape
Email Extension Plugin插件Email Extension Plugin插件@qq.com,可以跟发件人后缀不一致)Allow sending to unregistered usersUse SMTP Authenticationadmin@qq.comUse SSLHTML (text/html)Manage Jenkins-> Configure System-> Extended E-mail Notification
pipeline {
agent any
stages {
stage('Build') {
steps {
sh 'bash auto_test.sh'
}
}
}
post {
// 构建失败则发送邮件,接收方使用了gitlab的环境变量获取提交代码用户的用户名
failure {
emailext body: """<p>FAILED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]':</p>
<p>Check console output at "<a href="${env.BUILD_URL}">${env.JOB_NAME} [${env.BUILD_NUMBER}]</a>"</p>""",
subject: "[FAILED]: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]'",
to: "${env.gitlabUserName}"
}
}
}
至此,构建完成失败后自动发送邮件配置完成,如果想配置成无论构建成功与否都发送邮件,可以使用post里的always或者使用success+failure结合的方式实现。