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

Ok

I have a Jenkins work (a later version of Jenkins).

In my Jenkins work, I have a couple of parameters (string type).

Ex: param 1 = value 1 ... for parameter N = value N

Now, in Jenkins' assignment, in the BUILD section, I call " Invoke Gradle" .

In this section of Gradle, I invoke the task (s). For ex: clean build

I need: I want to pass the above Jenkins work parameters to Gradle as -PparamN = ValueN way?

But when I pass -Pparam1 = $ {param1} -Pparam2 = $ {param2} ... and so on in the "Toggles" option in the Gradle Build section, I see that the following is displayed in the Jenkins log:

It called Gradle is successfully processed with parameters.

...somepath.../bin/gradle -Dparam1=value1 -Dparam2=value2 ... -DparamN=valueN -Pparam1=value1 -Pparam2=value2 ... -PparamN=valueN 

This suggests that Jenkins is kind enough to pass parameters (which I defined in the task) to Gradle as "-D" for free.

My? s:

  • Well, I do not want to pass the above parameters as -Dxxx = yyy
  • I only want to pass the parameters -Pxxx = yyy way
  • Is this possible using the Invoke Gradle plugin?
+7
parameter-passing plugins parameters jenkins gradle
source share
3 answers

I assume that at the moment there is no way to tell the Jenkins Gradle plugin so as NOT to pass parameters (defined in Jenkins task) as -Dxxx = $ yyy way (which it does for us for free).

We can use the "switch" box / option to specify these parameters as -P, but this is a bit confusing how the -D parameters will affect the JVM, which Gradle uses to run and the -D parameters will somehow collide with the parameters - P (as they are transmitted / determined twice).

As a workaround, I stopped using the Gradle plugin and used the Run Shell option in the BUILD section and called the Gradle executable with the appropriate parameters (-P) and task (s).

This is an easy way to call Gradle with options and tasks, such as what you could run at the CMD or $ prompt.

+4
source share

Let Jenkins have the -D option first. And then you can switch to Gradle with -P. For example, if you have an env parameter, you can put it in the task as

  -Penv=${env} 
+1
source share

As in 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 choose to pass all parameters as Gradle properties, whatever you want.

enter image description here

0
source share

All Articles