Jenkinsfile java.lang.NullPointerException: 无法在空对象上调用方法 <printpn()>
Jenkinsfile java.lang.NullPointerException: Cannot invoke method <printpn()> on null object
我在下面有这个 Jenkinsfile,我正在尝试 运行 但它以某种方式抛出 "java.lang.NullPointerException: Cannot invoke method printpn() on null object"
错误。有人可以检查我遗漏了什么吗?
[jimmy@localhost]$ cat Jenkinsfile
#!groovy
pipeline {
agent any
stages {
stage('Load Groovy') {
steps {
script {
def func1 = load('prop.groovy')
func1.printpn()
}
}
}
}
}
[jimmy@localhost]$ cat prop.groovy
def printpn() {
sh """#!/usr/bin/env bash
echo "Coming from groovy function."
"""
}
您似乎忘记在 prop.groovy 文件中写入 "return this"。只需在末尾添加“return this
”这样
def printpn() {
sh """#!/usr/bin/env bash
echo "Coming from groovy function."
"""
}
return this
我在下面有这个 Jenkinsfile,我正在尝试 运行 但它以某种方式抛出 "java.lang.NullPointerException: Cannot invoke method printpn() on null object"
错误。有人可以检查我遗漏了什么吗?
[jimmy@localhost]$ cat Jenkinsfile
#!groovy
pipeline {
agent any
stages {
stage('Load Groovy') {
steps {
script {
def func1 = load('prop.groovy')
func1.printpn()
}
}
}
}
}
[jimmy@localhost]$ cat prop.groovy
def printpn() {
sh """#!/usr/bin/env bash
echo "Coming from groovy function."
"""
}
您似乎忘记在 prop.groovy 文件中写入 "return this"。只需在末尾添加“return this
”这样
def printpn() {
sh """#!/usr/bin/env bash
echo "Coming from groovy function."
"""
}
return this