如何用Jenkins发送电子邮件通知?

时间:2017-08-18 15:37:51

标签: email jenkins jenkins-plugins jenkins-pipeline

我想在构建失败时发送电子邮件。我已配置系统管理员电子邮件地址:test@gmail.com和 SMTP服务器:smtp.gmail.com。

这是我的代码:

pipeline{
agent none
stages{
    stage('test'){
        agent{
            label 'VStest'
        }
        steps{
            script{
                //nothing
            }
        }
    }
}
post{
    always{
        mail to: 'test@gmail.com',
            subject: "Failed Pipeline: ${currentBuild.fullDisplayName}",
            body: "Something is wrong with ${env.BUILD_URL}"
        echo "sent"
      }
   }
}

我收到错误:

  

com.sun.mail.smtp.SMTPSendFailedException:530 5.7.0必须先发出STARTTLS命令。

有人知道为什么吗? THX。

1 个答案:

答案 0 :(得分:2)

您使用的默认SMTP端口(25)不适用于Gmail帐户。尝试使用端口465进行SSL或将端口587用于TLS。

本指南可能有所帮助:http://www.360logica.com/blog/email-notification-in-jenkins/