John Stadt
John Stadt

Reputation: 510

Jenkins CLI Java API - specifiy build parameters

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

Upvotes: 3

Views: 4786

Answers (1)

John Stadt
John Stadt

Reputation: 510

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);

Upvotes: 3

Related Questions