steps scripted plugin examples example jenkins groovy jenkins-pipeline

scripted - Oleoducto Jenkins: No existe tal método DSL



scripted pipeline (1)

Con este código conseguí un error en la tubería de Jenkins. No lo entiendo porque ¿Me estoy perdiendo de algo?

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 }

Error:

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


eliminar los corchetes adicionales alrededor de la invocación 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 }

Actualizar:

En Groovy, si el último argumento de un método es de tipo Closure, al llamar al método, el cierre puede estar fuera de los paréntesis, como:

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 }

La razón por la que se lanza el original es porque el siguiente código

def whatThe = someFunc(''textToFunc'') {def whatThe2 = someFunc2(''textToFunc2'')}

es el mismo código que

def whatThe = someFunc(''textToFunc'') { def whatThe2 = someFunc2(''textToFunc2'') }

Esto significa que lo que el intérprete buscará es

someFunc(String text, Closure c)

y no hay tal método