How do you pass in command line parameters to a job dsl?

632 views
Skip to first unread message

Anoop Kulkarni

unread,
Sep 26, 2016, 1:31:01 PM9/26/16
to job-dsl-plugin

I have a job where I can pass in command line arguments like

gradle -Pconf=prod build


How do I pass arguments in jobs dsl?


I tried the following but it doesn't work

job("doSomething"){
    steps {
       gradle('-Pconf=prod build')
    }
}
job("doSomething"){
    steps {
       gradle('build', '-Pconf=prod')
    }
}
job("doSomething"){
    steps {
        gradle{
        tasks('build')
tasks('-Pconf=prod') } } }
job("doSomething"){
    steps {
        gradle{
        tasks('build')
switches('-Pconf=prod')
} } }
job dsl plugin version 1.48

Chris Doré

unread,
Sep 27, 2016, 4:46:18 PM9/27/16
to job-dsl-plugin
Could you further describe what isn't working?

All of the above examples you used are generating xml successfully in http://job-dsl.herokuapp.com/
#2 and #4 are the ideal choices because they correctly configure tasks vs switches in the plugin.


Chris

Anoop Kulkarni

unread,
Sep 28, 2016, 2:33:00 PM9/28/16
to job-dsl-plugin
It doesn't recognize the -P variable being passed in.

In my case its ignoring conf=prod and uses conf=local which is specified in gradle.properties

Chris Doré

unread,
Sep 28, 2016, 2:49:15 PM9/28/16
to job-dsl-plugin
Hmm, can you double check the gradle command being executed?
When the generated job executes, the console output should show you the gradle command being run. Does it appear correct?

Anoop Kulkarni

unread,
Sep 28, 2016, 3:19:24 PM9/28/16
to job-dsl-plugin
yep, I print the variable value in the task.

When I run it from the command line gradle -Pconf=prod build, it prints 'prod'

When I run it from jenkins it prints 'local'

Chris Doré

unread,
Sep 28, 2016, 3:39:59 PM9/28/16
to job-dsl-plugin
I don't think this is a job dsl issue. Does the same behaviour exist if you manually create a job in jenkins that runs your gradle build?

It doesn't look like you're using the gradle wrapper. Could it be that jenkins and your command line are using different versions of gradle? What happens if you run your gradle command from the same system that Jenkins is?

Anoop Kulkarni

unread,
Oct 3, 2016, 3:46:47 PM10/3/16
to job-dsl-plugin
In jobs dsl I tried using wrapper

   gradle{
      useWrapper
(true)

      tasks
('build')
      switches
('-Pconf=prod')
   
}
 but it still wont take the switch argument

When I create a manual job in jenkins and pass in -Pconf=prod in the switches section it works fine. So I dont think this problem is external to gradle or jenkins.

Victor Martinez

unread,
Oct 3, 2016, 5:49:20 PM10/3/16
to job-dsl-plugin
As far as i see:
http://jenkinsci.github.io/job-dsl-plugin/#method/javaposse.jobdsl.dsl.helpers.step.StepContext.gradle

Version 1.23+, what gradle.plugin version is installed in your jenkins instance?

Cheers

Anoop Kulkarni

unread,
Oct 3, 2016, 6:34:19 PM10/3/16
to job-dsl-plugin
gradle plugin: 1.24

Found the issue (something which I should have caught earlier)

My repo has the groovy job dsl and on every commit it triggered a build. I was concentrating on the build output without realizing that the gradle configuration section didn't change on each build. The job was created by a seed job which hasn't run since the seed run and the job configuration hasn't been updated since.

Thanks for the remark about gradle plugin, making me to look at the gradle configuration. Re-ran the seed job and now everything works great. 

Sorry for the bother.
Reply all
Reply to author
Forward
0 new messages