Jenkins库:java.lang.NullPointerException:无法在空对象上调用方法xxx [英] Jenkins library: java.lang.NullPointerException: Cannot invoke method xxx on null object

查看:374
本文介绍了Jenkins库:java.lang.NullPointerException:无法在空对象上调用方法xxx的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用声明性管道和单独的pipline助手.在其中一个助手中,我的文件vars/getTriggerCause.groovy与

I am using declarative pipelines and separate pipline helpers. In one of the helper I have the file vars/getTriggerCause.groovy with

/**
* Checks for cause of the job trigger and returns respective cause
* @return user, scm, time or other
*/
def String getCause() {
    echo "CAUSE ${currentBuild.rawBuild.getCauses().properties}"
    def cause = "${currentBuild.rawBuild.getCauses()}"
     if (cause =~ "UserIdCause") {
         return "user"
    }
}

/**
* Checks if trigger cause of the job is the timer
* @return true if trigger is timer
*/
def boolean isTime() {
    return this.call() == "time"
}

现在我要像这样在Jenkisfile中使用该功能

Now I want to use the function in the Jenkisfile like this

echo getTriggerCause().isTime()

这将导致NPE:

java.lang.NullPointerException: Cannot invoke method getCause() on null object

当我查看时,我会期望这项工作.与链接示例的唯一区别是,我从scm动态加载了库.

When I look at this I would expect this works. The only difference to the linked example is that I load the library dynamically from scm.

推荐答案

删除括号即可解决此问题,

Removing the parentheses solve the problem so this works

getTriggerCause.isTime()

这篇关于Jenkins库:java.lang.NullPointerException:无法在空对象上调用方法xxx的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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