Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing a parameter from Jenkins into Java

Tags:

java

jenkins

We've set up some parameters for executing a build in Jenkins (using the simple "parameterized build" setting). The job is set up as Maven test. Is there a way to programmatically pass those parameters into our Java code? We need to execute certain update functions based on the parameter set via Jenkins.

like image 794
rs79 Avatar asked Nov 28 '25 00:11

rs79


1 Answers

Yes you can pass your Jenkins parameters to your Java code through the maven execution like this:

mvn clean test -Dparam1=$JOB_PARAM_1

Note that the $JOB_PARAM_1 will capture the value of the parameter set on Jenkins. This is for Unix environments, if you are working with Jenkins on Windows, then use %JOB_PARAM_1% instead.

like image 129
brunocrt Avatar answered Nov 29 '25 13:11

brunocrt