在Jenkins管道上发送邮件 [英] Sending a Mail on Jenkins Pipeline

查看:333
本文介绍了在Jenkins管道上发送邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的管道作业,应该发送邮件,我在Manage jenkins-> Configure System上配置了端口465和相应的SMTP服务器,当我通过发送电子邮件测试配置时,它会发送并可以在我的收件箱中看到测试邮件,但是从管道作业来看,它失败了:

hi I have a simple pipeline job that should send a mail, I configured on Manage jenkins -> Configure System with port 465 and the appropriated SMTP server , when I test the configuration by sending a e-mail , it sends and I can see the test mail on my inbox , but from the pipeline job , it fails:

node {

    stage("test") {
        def message = "hello there!" 

        mail bcc: '', body: message, cc: '', from: 'jenkinsuser@mycom.com', replyTo: 'jenkinsuser@mycom.com', subject: "Develop: build generated ",     to:'grace@mycom.com'
    }

}

错误:

java.net.SocketException: Connection closed by remote host
    at sun.security.ssl.SSLSocketImpl.checkWrite(Unknown Source)
    at sun.security.ssl.AppOutputStream.write(Unknown Source)
    at com.sun.mail.util.TraceOutputStream.write(TraceOutputStream.java:114)
    at java.io.BufferedOutputStream.flushBuffer(Unknown Source)
    at java.io.BufferedOutputStream.flush(Unknown Source)
    at com.sun.mail.smtp.SMTPTransport.sendCommand(SMTPTransport.java:2104)
Caused: javax.mail.MessagingException: Can't send command to SMTP host;
  nested exception is:
    java.net.SocketException: Connection closed by remote host
    at com.sun.mail.smtp.SMTPTransport.sendCommand(SMTPTransport.java:2106)
    at com.sun.mail.smtp.SMTPTransport.sendCommand(SMTPTransport.java:2093)
    at com.sun.mail.smtp.SMTPTransport.close(SMTPTransport.java:1184)

任何建议如何解决?

谢谢

推荐答案

我正在使用电子邮件扩展插件没有问题。确保已正确配置管理Jenkins>配置系统中的电子邮件通知部分。 gmail的示例:
Jenkins电子邮件通知设置

I am using Email Extension plugin in scripted pipeline with no issues. Make sure you properly configured E-mail Notification section in Manage Jenkins > Configure System. Example for gmail: Jenkins e-mail notifications settings

此处描述了插件的用法:此处。这就是我在管道中调用它的方式(我没有删除变量):

Plugin usage is described here: here. This is how I call it in Pipeline (I didn't remove variables):

emailext attachmentsPattern: "**/packages/rpm/splitted/${file}",
              to: "${to}",
            from: "Jenkins",
         subject: "[jenkins] ${packageFullName}: part ${part}/${files.size()}",
            body: "File received: \'${file}\'\n" +
                  "From package:  \'${packageFullName}\'\n" +
                  "Package MD5:   \'${mainMdFiveSum}\'\n" +
                  "Jenkins Build: \'${env.BUILD_URL}\'\n"

这篇关于在Jenkins管道上发送邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆