我正在使用声明性管道和单独的管道助手。在助手之一,我有一个文件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"
}
Run Code Online (Sandbox Code Playgroud)
现在我想像这样使用 Jenkisfile 中的函数
echo getTriggerCause().isTime()
Run Code Online (Sandbox Code Playgroud)
这会导致 NPE:
java.lang.NullPointerException: Cannot invoke method getCause() on null object
Run Code Online (Sandbox Code Playgroud)
当我看到这个时,我希望这有效。与链接示例的唯一区别是我从 scm 动态加载库。