You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Jenkins构建后操作触发NullPointerException问题求助

问题:Jenkins Notify.Events插件构建后操作触发NullPointerException

无法定位Jenkins中使用Notify.Events插件发送报告时,构建后操作出现NullPointerException的原因,恳请协助解决。

我的Pipeline配置如下:

post {
    always {
        step([$class: 'Publisher', reportFilenamePattern: '**/testng-results.xml'])
    }
    unstable {
        step([$class: 'NotifyEventsBuilder', token: '6CGdLVTZUPWaQsz7qIGN52KRHSDuYdup', message: 'UNSTABLE TEST'])
    }
    failure {
        step([$class: 'NotifyEventsBuilder', token: '6CGdLVTZUPWaQsz7qIGN52KRHSDuYdup', message: 'FAIL TEST'])
    }
    success {
        step([$class: 'NotifyEventsBuilder', token: '6CGdLVTZUPWaQsz7qIGN52KRHSDuYdup', message: 'SUCCESSFUL TEST'])
    }
    unsuccessful {
        step([$class: 'NotifyEventsBuilder', token: '6CGdLVTZUPWaQsz7qIGN52KRHSDuYdup', message: 'unsuccessful TEST'])
    }
}

执行报错信息:

[Pipeline] step
Error when executing success post condition:
java.lang.NullPointerException
    at events.notify.NotifyEventsService.send(NotifyEventsService.java:159)
    at events.notify.NotifyEventsBuilder.perform(NotifyEventsBuilder.java:138)
    at jenkins.tasks.SimpleBuildStep.perform(SimpleBuildStep.java:123)
    at org.jenkinsci.plugins.workflow.steps.CoreStep$Execution.run(CoreStep.java:101)
    at org.jenkinsci.plugins.workflow.steps.CoreStep$Execution.run(CoreStep.java:71)
    at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution.lambda$start$0(SynchronousNonBlockingStepExecution.java:47)
    at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at java.base/java.lang.Thread.run(Thread.java:834)

[Pipeline] step
Error when executing unsuccessful post condition:
java.lang.NullPointerException
    at events.notify.NotifyEventsService.send(NotifyEventsService.java:159)
    at events.notify.NotifyEventsBuilder.perform(NotifyEventsBuilder.java:138)
    at jenkins.tasks.SimpleBuildStep.perform(SimpleBuildStep.java:123)
    at org.jenkinsci.plugins.workflow.steps.CoreStep$Execution.run(CoreStep.java:101)
    at org.jenkinsci.plugins.workflow.steps.CoreStep$Execution.run(CoreStep.java:71)
    at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution.lambda$start$0(SynchronousNonBlockingStepExecution.java:47)
    at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at java.base/java.lang.Thread.run(Thread.java:834)

[Pipeline] step
Error when executing failure post condition:
java.lang.NullPointerException
    at events.notify.NotifyEventsService.send(NotifyEventsService.java:159)
    at events.notify.NotifyEventsBuilder.perform(NotifyEventsBuilder.java:138)
    at jenkins.tasks.SimpleBuildStep.perform(SimpleBuildStep.java:123)
    at org.jenkinsci.plugins.workflow.steps.CoreStep$Execution.run(CoreStep.java:101)
    at org.jenkinsci.plugins.workflow.steps.CoreStep$Execution.run(CoreStep.java:71)
    at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution.lambda$start$0(SynchronousNonBlockingStepExecution.java:47)
    at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at java.base/java.lang.Thread.run(Thread.java:834)

[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
java.lang.NullPointerException
    at events.notify.NotifyEventsService.send(NotifyEventsService.java:159)
    at events.notify.NotifyEventsBuilder.perform(NotifyEventsBuilder.java:138)
    at jenkins.tasks.SimpleBuildStep.perform(SimpleBuildStep.java:123)
    at org.jenkinsci.plugins.workflow.steps.CoreStep$Execution.run(CoreStep.java:101)
    at org.jenkinsci.plugins.workflow.steps.CoreStep$Execution.run(CoreStep.java:71)
    at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution.lambda$start$0(SynchronousNonBlockingStepExecution.java:47)
    at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at java.base/java.lang.Thread.run(Thread.java:834)
Finished: FAILURE

解决方案分析与修复

  • 改用插件标准流水线步骤:当前通过step([$class: 'NotifyEventsBuilder'])的反射调用方式容易遗漏必填参数,建议使用插件提供的标准notifyEvents步骤。
  • 补充必填参数:空指针异常大概率是缺少title参数导致,插件内部可能依赖该字段进行通知内容组装。
  • 修复后的Pipeline示例:
post {
    always {
        step([$class: 'Publisher', reportFilenamePattern: '**/testng-results.xml'])
    }
    unstable {
        notifyEvents token: '6CGdLVTZUPWaQsz7qIGN52KRHSDuYdup', title: 'Jenkins构建通知', message: 'UNSTABLE TEST'
    }
    failure {
        notifyEvents token: '6CGdLVTZUPWaQsz7qIGN52KRHSDuYdup', title: 'Jenkins构建通知', message: 'FAIL TEST'
    }
    success {
        notifyEvents token: '6CGdLVTZUPWaQsz7qIGN52KRHSDuYdup', title: 'Jenkins构建通知', message: 'SUCCESSFUL TEST'
    }
    unsuccessful {
        notifyEvents token: '6CGdLVTZUPWaQsz7qIGN52KRHSDuYdup', title: 'Jenkins构建通知', message: 'unsuccessful TEST'
    }
}
  • 额外排查点:
    1. 检查Jenkins全局配置中Notify.Events插件的基础设置是否完整,比如默认通知端点是否配置。
    2. 尝试升级插件到最新稳定版本,排除旧版本的已知bug。
    3. 验证token的有效性,确保在Notify.Events平台上可以正常使用该token发送测试通知。

内容的提问来源于stack exchange,提问作者Ariyan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.15 17:25:18