Is it possible to use the script console or Jenkins CLI groovy command to execute Job DSL?

1,175 views
Skip to first unread message

Darren Bowen

unread,
Jun 4, 2016, 3:42:50 PM6/4/16
to job-dsl-plugin

I'm wondering if anyone knows whether it's possible to run job DSL from the Jenkins Script Console? Ideally I'd like to be able to run a groovy script from the command line using the Jenkins CLI 'groovy' command such that I can automate the creation of certain jobs.

I have the following script so far, which feels like it might be close. This runs, but produces an error in the jenkins log:
java.io.IOException: Unable to read C:\Program Files (x86)\Jenkins1.651\jobs\project-a\config.xml

It should be creating the file, so I'm not sure why it fails to read it, but it would be good to know if I'm on the right track?

import javaposse.jobdsl.dsl.*
import  javaposse.jobdsl.plugin.*

JenkinsJobManagement jm = new JenkinsJobManagement(System.out, [:], new File('.'));
DslScriptLoader dslScriptLoader = new DslScriptLoader(jm)
dslScriptLoader.runScript("folder('project-a')")


Message has been deleted

Will Jackson

unread,
Jun 6, 2016, 9:22:19 AM6/6/16
to job-dsl-plugin
This should run fine in script console. If you're running Jenkins as a Windows service, make sure the user you're running it as has permissions for that folder.

Darren Bowen

unread,
Jun 7, 2016, 5:06:34 AM6/7/16
to job-dsl-plugin
Many thanks this must be it as I just tried it on my linux server and it worked perfectly.
Reply all
Reply to author
Forward
0 new messages