Issue
I am unable to execute following script in jenkins script consol.
job('testjob') {
using('template_job')
configure { node ->
node / scm / branches / 'hudson.plugins.git.BranchSpec' / name('main')
}
}
groovy.lang.MissingMethodException: No signature of method: Script1.job() is applicable for argument types: (java.lang.String, Script1$_run_closure1) values: [testjob, Script1$_run_closure1@4eaafbe6]
Possible solutions: run(), run(), any(), wait(), dump(), grep()
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:58)
at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:81)
Solution
The script you are trying to run is a Job DSL script.
It is not intended to run in the Jenkins script console menu and therefore you get that exception, the DSL script should be executed in a dedicated Process Job DSLs build step (usually in a freestyle job). Use the following Official Documentation Guide to get started with the Jon DSL plugin and instructions on how to use it.
In addition here is an excellent Tutorial for using the Job DSL Plugin.
BTW, you can use the Job DSL Playground to create and test your configure blocks, but the playground only supports the DSL API that is available in the online API Reference - as oppose to the complete DSL API reference that is available in your Jenkins installation at https://your.jenkins.installation/plugin/job-dsl/api-viewer/index.html.
Answered By - Noam Helmer
Answer Checked By - Mary Flores (JavaFixing Volunteer)