Jenkins Gradle Plugin - Pass parameters as -P instead of -D Jenkins Gradle Plugin - Pass parameters as -P instead of -D jenkins jenkins

Jenkins Gradle Plugin - Pass parameters as -P instead of -D


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.

enter image description here


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}