このコードでは、Jenkinsパイプラインでエラーが発生しました。どうして?何か不足していますか?
node {
stage 'test'
def whatThe = someFunc('textToFunc')
{def whatThe2 = someFunc2('textToFunc2')}
}
def someFunc(String text){
echo text
text
}
def someFunc2(String text2){
echo text2
text2
}
エラー:
Java.lang.NoSuchMethodError: **No such DSL method 'someFunc'** found among [archive, bat, build, catchError, checkout, deleteDir, dir, echo, emailext, emailextrecipients, error, fileExists, git, input, isUnix, load, mail, node, parallel, properties, pwd, readFile, readTrusted, retry, sh, sleep, stage, stash, step, svn, timeout, timestamps, tool, unarchive, unstash, waitUntil, withCredentials, withEnv, wrap, writeFile, ws]
at org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.Java:124)
at org.jenkinsci.plugins.workflow.cps.CpsScript.invokeMethod(CpsScript.Java:117)
at groovy.lang.MetaClassImpl.invokeMethodOnGroovyObject(MetaClassImpl.Java:1280)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.Java:1174)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.Java:1024)
at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.Java:42)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.Java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.Java:113)
at com.cloudbees.groovy.cps.sandbox.DefaultInvoker.methodCall(DefaultInvoker.Java:15)
at WorkflowScript.run(WorkflowScript:4)
at ___cps.transform___(Native Method)
at com.cloudbees.groovy.cps.impl.ContinuationGroup.methodCall(ContinuationGroup.Java:55)
at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.Java:106)
at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixArg(FunctionCallBlock.Java:79)
at Sun.reflect.GeneratedMethodAccessor878.invoke(Unknown Source)
at Sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at Java.lang.reflect.Method.invoke(Unknown Source)
at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.Java:72)
at com.cloudbees.groovy.cps.impl.ClosureBlock.eval(ClosureBlock.Java:40)
at com.cloudbees.groovy.cps.Next.step(Next.Java:58)
at com.cloudbees.groovy.cps.Continuable.run0(Continuable.Java:154)
at org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.Java:164)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.Java:360)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$100(CpsThreadGroup.Java:80)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.Java:236)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.Java:226)
at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.Java:47)
at Java.util.concurrent.FutureTask.run(Unknown Source)
at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.Java:112)
at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.Java:28)
at Java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at Java.util.concurrent.FutureTask.run(Unknown Source)
at Java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at Java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at Java.lang.Thread.run(Unknown Source)
Finished: FAILURE
sumfunc2
呼び出しの周りから余分な角かっこを削除します。
node {
stage 'test'
def whatThe = someFunc('textToFunc')
def whatThe2 = someFunc2('textToFunc2')
}
def someFunc(String text){
echo text
text
}
def someFunc2(String text2){
echo text2
text2
}
更新:
Groovyでは、メソッドの最後の引数のタイプがClosureである場合、メソッドを呼び出すとき、次のようにクロージャーを角括弧の外にすることができます。
def foo(whatever, Closure c) {}
// Can be invoked as
foo(whatever, {
// This is the second argument of foo of type Closure
})
// It is also the same as writing
foo(whatever) {
// This is the second argument of foo of type Closure
}
オリジナルがスローされる理由は、次のコード
def whatThe = someFunc('textToFunc')
{def whatThe2 = someFunc2('textToFunc2')}
と同じコードです
def whatThe = someFunc('textToFunc') {
def whatThe2 = someFunc2('textToFunc2')
}
これは、インタープリターが探しているのは
someFunc(String text, Closure c)
そして、そのような方法はありません