Jenkins管道发送电子邮件错误“java.lang.NoSuchMethodError”,

tvz2xvvm  于 2023-02-03  发布在  Jenkins
关注(0)|答案(2)|浏览(223)

当我使用管道发送邮件时,Jenkins控制台输出**“java.lang.NoSuchMethodError”**,我认为这可能是邮件插件或Jenkins版本引起的,但我不确定,所以我如何操作?
管线

pipeline {
        agent any
        stages {
            stage('Hello') {
                steps {
                    echo "Hello world"
                        }
                }
            }
        post{
            always{
                mail to: "15283666096@163.com",
                subject: "Test Email",
                body: "Test"
            }
        }
    }

输出

[Pipeline] { (Declarative: Post Actions)
[Pipeline] mail
Error when executing always post condition:
java.lang.NoSuchMethodError: 'jenkins.plugins.mailer.tasks.MimeMessageBuilder jenkins.plugins.mailer.tasks.MimeMessageBuilder.addRecipients(java.lang.String, javax.mail.Message$RecipientType)'
    at org.jenkinsci.plugins.workflow.steps.MailStep$MailStepExecution.buildMimeMessage(MailStep.java:167)
    at org.jenkinsci.plugins.workflow.steps.MailStep$MailStepExecution.run(MailStep.java:142)
    at org.jenkinsci.plugins.workflow.steps.MailStep$MailStepExecution.run(MailStep.java:129)
    at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution.lambda$start$0(SynchronousNonBlockingStepExecution.java:47)
    at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
    at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.base/java.lang.Thread.run(Unknown Source)

[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
zte4gxcn

zte4gxcn1#

从下面的文档中可以看到,邮件插件没有“mail to“属性。
您能否尝试使用“to“属性而不是“mail to“进行相同的配置?

ezykj2lf

ezykj2lf2#

您可能有更新版本的Mailer和旧版本的Pipeline Basic Steps
问题出在从Pipeline Basic Steps插件调用Mailer的过程中。

org.jenkinsci.plugins.workflow.steps.MailStep$MailStepExecution.buildMimeMessage(MailStep.java:167)

在这个commit中,它们从 * javax.mail * 迁移到 * jakarta.mail *。
因此,较早版本的Pipeline Basic Steps使用javax.mail.Message$RecipientType类型的参数而不是jakarta.mail.Message$RecipientType进行调用。
下面是类MimeMessageBuilder的最新版本,方法为addRecipients(java.lang.String, jakarta.mail.Message$RecipientType)
我更新了具有Pipeline Basic Steps依赖项的Pipeline插件,使其工作。

相关问题