OK
I have a Jenkins job (Jenkins version more recent).
In my Jenkins job, I have couple of parameters (string type).
Ex: param1=value1 ... to paramN=valueN
Now, in Jenkins job, under BUILD section, I'm calling "Invoke Gradle".
In this Gradle section, I'm calling a task(s). For ex: clean build
What I need is: I want to pass the above Jenkins job's parameters to Gradle as -PparamN=ValueN way?
But when I'm passing -Pparam1=${param1} -Pparam2=${param2} ...and so on in "Switches" option in Gradle Build section, I see Jenkins log is showing:
It called Gradle exectuable successfully with the parameters.
...somepath.../bin/gradle -Dparam1=value1 -Dparam2=value2 ... -DparamN=valueN -Pparam1=value1 -Pparam2=value2 ... -PparamN=valueN
This tell, Jenkins is kind enough to pass the parameters(which I have defined in the job) to Gradle as "-D" way for free.
My ?s:
I guess at this time, there is no way to tell Gradle plugin in Jenkins to NOT pass the parameters (defined in Jenkins job) as -Dxxx=$yyy way (which it's doing for us for free).
We can though, use "switches" box/option to specify these parameters as -P way but it's little confusing how -D parameters will impact the JVM which Gradle uses to run itself and whether -D parameters will somehow clash with -P parameters (as they are getting passed / defined twice).
As a workaround, I stopped using Gradle plugin and used "Execute Shell" option under BUILD section and called gradle executable with the respective parameters (-P way) and task(s).
This is just a plain way of calling Gradle with parameters and tasks like what you'd run at CMD or $ prompt.
As with the Jenkins Gradle plugin 1.27 there is a checkbox to tell the plugin not to pass parameters as system properties and add some parameters manually. You can also select to pass all parameters as Gradle properties what would be what you probably want.
Let Jenkins have the parameter as -D first. And then you can pass to Gradle with -P. For example, if you have a parameter called env, you can put it in the task as
-Penv=${env}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With