Hi I have written a shellscript which accepts the "jenkins job name" and starts triggering that build via command line , In my Jenkins server I have different jobs which differs in count and names of parameters.
$build_name= Jenkins_job_name ##(which is the only input)
java -jar jenkins-cli.jar -s http://mydomain:8080/ build $build_name -s -p PARA1=$paravalue
will work only if i am giving the exact name and count of the parameter which the job expects
I want to generalize this build triggering script, which fetches the names of parameter for a specific job,accepts it and then triggers the build
NB: When I try the above script with different parameter name ("KEY1" instead of "PARA1"), I am getting the message like:
'KEY1' is not a valid parameter. Did you mean "PARA1"?
You can use the
get-job $build_name
on the cli to get the job configurationThe parameters are under:
<parameterDefinitions> <name>PARA1</name>
There will be multiple instances of
<name>...</name>
Alternatively, you can make a call to
http://mydomain:8080/job/$build_name/api/json
The parameters will be in format:
"parameterDefinitions":[{..., "name":"PARA1", ...}, ...]
There will be multiple instances of
{..., "name":"...", ...},
Parse the file to get all parameters defined for the job. The json format is either for shell since it is all on a single line. A RegEx can detect the start of
parameterDefinitions
and get the followingname
values, before the end of brackets.