声明式管道发送电子邮件

Rty*_*yUP 5 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."
        }
    }   
}  
Run Code Online (Sandbox Code Playgroud)

但是当我执行时,出现以下错误:

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
Run Code Online (Sandbox Code Playgroud)

我想我不能在端口25上发送,我需要在端口465上发送。我错了吗?但是我不知道该怎么办。

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

建议?

小智 3

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

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

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