Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

fetching parameters from a jenkins job in java code

I have a parameterised jenkins job that is accessing my plugin. Inside plugin's code in java, i require these parameters using which i have to trigger another job in jenkins. I am not able to fetch these parameters and it is a very high priority issue now. I ahve tried multiple solutions available on stackoverflow, for eg., tried accessing the environment variables but didn't received the param's value. for e.g., my parameter is 'REPOS' and i need its value, i have tried :

System.getProperty("REPOS");

but it returns null.

Also, tried :

Map<String, String> env = System.getenv();
              for (String envName : env.keySet()) {
                  System.out.format("%s=%s%n", envName, env.get(envName));
              }

but it prints the jenkins' environment variables and not the job's parameters.

I am referring to the value passed in the text box beside param: "url" in the below picture.

enter image description here

Please assist.

like image 823
sonal Avatar asked Nov 22 '25 15:11

sonal


1 Answers

Thanks for the suggestions, but it worked when i did the following: I hit the

JENKINS_HOST_URL/job/JENKINS_SEED_JOB_NAME/api/json?pretty=true

and found the current build number, thereafter, hitting jenkins again with this number(JENKINS_HOST_URL/job/JENKINS_SEED_JOB_NAME/currBuildNum/api/json?pretty=true),

I was able to fetch all the parameters passed in there in this build.

like image 61
sonal Avatar answered Nov 25 '25 04:11

sonal