1
votes

I am using below Groovy Script in Jenkins Pipeline to call a Free style job but it ends up with "No such DSL method 'build'" error.

node{
       def branches = [:] 
       List rows =["Test2", "Test1"] 
       for (int i = 0; i <rows.size(); i++) 
       { 
         def index = i  
         String db = rows[i] 
         branches["branch${i}"] = { 
             build job: 'CopyFile', parameters: [[$class:  
            'StringParameterValue', name:  'DatabaseName', value: db], [$class: 
            'StringParameterValue', name:'dummy', value: "${index}"]] 
       } 
   } 
   parallel branches
}   
1
I'm unable to reproduce this, a similar (simplified) versions works as expected for me. Can you add the stacktrace?Jon S
at org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:149) at org.jenkinsci.plugins.workflow.cps.CpsScript.invokeMethod(CpsScript.java:108) 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 groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:812) at groovy.lang.GroovyObjectSupport.invokeMethod(GroovyObjectSupport.java:46) at groovy.lang.MetaClassImpl.invokeMethodOnGroovyObject(MetaClassImpl.java:1280)Iniyaa Karthikeyan
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:18) at WorkflowScript.run(WorkflowScript:18)Iniyaa Karthikeyan
at ___cps.transform___(Native Method) at com.cloudbees.groovy.cps.impl.ContinuationGroup.methodCall(ContinuationGroup.java:57) at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.java:109) at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixArg(FunctionCallBlock.java:82) at sun.reflect.GeneratedMethodAccessor37.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source)Iniyaa Karthikeyan
Umm, unsure what the problem is here. However, it seems like the example above isn't what you are actually running considering WorkflowScript:18 in the stacktrace, e.g. there are at-least 18 lines in the one you run, above script doesn't have 18 lines. Have you tried the script above?Jon S

1 Answers