声明性管道发送电子邮件

时间:2017-12-04 21:23:36

标签: email jenkins

我需要使用jenkins发送邮件通知(如果是成功构建或出错了)

现在我有类似的东西:

pipeline {
    agent any

...Some stages ...

post {
        success {
            mail to:"someone@hotmail.com", subject:"SUCCESS: ${currentBuild.fullDisplayName}", body: "Yay, we passed."
        }
        failure {
            mail to:"someone@hotmail.com", subject:"FAILURE: ${currentBuild.fullDisplayName}", body: "Boo, we failed."
        }
    }   
}  

但是当我执行时我得到以下错误:

java.net.ConnectException: Connection refused: connect
Caused: javax.mail.MessagingException: Could not connect to SMTP host: localhost, port: 25;
  nested exception is:
    java.net.ConnectException: Connection refused: connect

我想我无法发送端口25我需要将它发送到端口465 ..我错了吗?但我不知道我该怎么做。

在大多数示例中,他们使用jenkins的插件,但我可以仅使用代码(声明性管道

建议?

2 个答案:

答案 0 :(得分:1)

Jenkins默认电子邮件服务器尝试在端口25上运行您的localhost。正如您所猜测的那样,该错误消息表明您需要更改电子邮件设置。

为此,请转到管理Jenkins - > 配置系统 - > 电子邮件通知扩展电子邮件通知

顺便说一句,除非你有一个本地运行的电子邮件服务器(如果是这种情况我会感到惊讶),更改本地端口号将不起作用。您需要将其指向外部服务器。 Here是Jenkins使用Google SMTP服务器的设置页面,例如

答案 1 :(得分:0)

您可能必须让Jenkins master 发送电子邮件(大多数代理/节点可能没有邮件服务器):

success {
    node("master") { 
        mail ...
    }
}