我有一个像这样的管道脚本:
node('linux'){
stage('Setup'){
echo "Build Stage"
} stage('Build'){
echo "Build Stage"
} stage('Test'){
echo "Test Stage"
}
}
Setup
阶段运行良好但在此之后抛出异常
java.lang.NullPointerException: Cannot invoke method stage() on null object
at org.codehaus.groovy.runtime.NullObject.invokeMethod(NullObject.java:91)
at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:48)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.NullCallSite.call(NullCallSite.java:35)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:157)
at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:159)
at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.methodCall(SandboxInvoker.java:17)
at WorkflowScript.run(WorkflowScript:2)
at ___cps.transform___(Native Method)
at com.cloudbees.groovy.cps.impl.ContinuationGroup.methodCall(ContinuationGroup.java:57)
可能出错?
答案 0 :(得分:2)
public ArrayList getCopy(ArrayList <Item> listToCopy)
{
if(null == listToCopy)
{
// Handle this option too
}
ArrayList <Item> copy = new ArrayList(listToCopy.size());
for(Item item : listToCopy)
{
// It is important that your class "Item" contains a copy constructor
copy.add(new Item(item));
}
return copy;
}
stage('Setup'){
echo "Build Stage"
} stage('Build'){
是一个返回stage
的方法调用。您null
对象的stage('Build'){
正在尝试调用null
,这就是您获取NullPointerException
的原因。
将您的stage
调用移至新行,或添加分号以分隔语句。
stage('Setup'){
echo "Build Stage"
}; stage('Build'){
stage('Setup'){
echo "Build Stage"
}
stage('Build'){