Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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:

  1. Well, I don't want to pass the above parameters as -Dxxx=yyy
  2. I want to pass the parameters only -Pxxx=yyy way
  3. Is this possible with using "Invoke Gradle" plugin?
like image 464
AKS Avatar asked Dec 30 '14 22:12

AKS


3 Answers

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.

like image 150
AKS Avatar answered Oct 07 '22 18:10

AKS


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

like image 37
wolfs42 Avatar answered Oct 07 '22 17:10

wolfs42


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}
like image 31
user1695166 Avatar answered Oct 07 '22 18:10

user1695166