Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins CLI Java API - specifiy build parameters

Tags:

java

jenkins

Given i.e. this code::

...
List<String> arguments = new LinkedList<String>();
arguments.add("build");
arguments.add(projectName);
arguments.add("-s");
arguments.add("-v");
CLI cli  = new CLI(new URL(url));
cli.upgrade();
int exit_code = cli.execute(arguments);
...

how can I specify build parameters for a parametrized jenkins build? adding i.e. arguments.add("-p options.properties=system.props"); to the list doesn't work /message is '

-p options.properties=system.props is not a valid option

'/

What I am trying to achieve above works fine from command line :::

java -jar jenkins-cli.jar -s http://localhost:8080/jenkins build mvn_project01 -p options.properties=system.props
like image 784
John Stadt Avatar asked Apr 11 '26 04:04

John Stadt


1 Answers

to answer my own question::

apparently parameters and parameter values must go into the list as separate entries. The below code will asynchronously invoke a remote jenkins build with 2 parameters, print the console output and return the exit code;

List<String> arguments = new LinkedList<String>();
arguments.add("build");
arguments.add(projectName);

arguments.add("-p");
arguments.add("options.properties=system.props");
arguments.add("-p");
arguments.add("anotherOption=optionValue");

arguments.add("-s");
arguments.add("-v");
CLI cli  = new CLI(new URL(url));
cli.upgrade();
int exit_code = cli.execute(arguments);
like image 199
John Stadt Avatar answered Apr 13 '26 16:04

John Stadt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!