I’m trying to fully automate the creation of Jenkins. I got most of the setup working using groovy scripts. My last hurdle is creating a job using the DSL. I’m able to create the job using xml via:
def jobName = "jobname"
String configXml = new File('/jobname.xml').getText('UTF-8')
def xmlStream = new ByteArrayInputStream( configXml.getBytes() )
However, the XML file is hard to maintain and not easy to understand. So I wanted to switch to use DSL syntax, but I can’t fix an API to replace createProjectFromXML(…) with something like createPrjectFromDSL?
My question is how to create a new job using DSL? I got this part working, thank you.
However my next question is where do I put this file so Jenkins will create the job on startup? When i try to copy it to /var/jenkins_home/init.groovy.d I get the following exception on startup:
WARNING: Failed to run script file:/var/jenkins_home/init.groovy.d/neoconfig-dsl.groovy
groovy.lang.MissingMethodException: No signature of method: neoconfig-dsl.job() is applicable for argument types: (java.lang.String, neoconfig-dsl$_run_closure1) values: [neo, neoconfig-dsl$_run_closure1@7d799f93]
Possible solutions: run(), run(), any(), wait(), grep(), dump()