簡體   English   中英

Jenkins 庫:java.lang.NullPointerException:無法在空對象上調用方法 xxx

[英]Jenkins library: java.lang.NullPointerException: Cannot invoke method xxx on null object

我正在使用聲明性管道和單獨的管道助手。 在其中一個助手中,我有文件vars/getTriggerCause.groovy

/**
* 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 中的函數

echo getTriggerCause().isTime()

這會導致 NPE:

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

當我看到這個時,我希望這有效。 與鏈接示例的唯一區別是我從 scm 動態加載庫。

我在使用 load 時收到了類似的錯誤消息,問題是我忘記從 groovy 文件中返回this

刪除括號解決了這個問題

getTriggerCause.isTime()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM