jenkinsci / java-client-api

A Jenkins API client for Java
MIT License
896 stars 468 forks source link

No way to get the job parameters? #470

Open dtrunk90 opened 3 years ago

dtrunk90 commented 3 years ago

Shouldn't the parameters be part of the JobWithDetails object?

vikas981 commented 3 years ago

You can get job parameters if your job already executed once

   public static Map<String, String> getParameter(String jenkinsUrl, String userName, String passWord, String jobName) {
    Map<String, String> hashMap = new HashMap<String, String>();
    try {
        JenkinsServer jenkinsServer = new JenkinsServer(new URI(jenkinsUrl),userName,passWord);
        JobWithDetails jobWithDetails = jenkinsServer.getJob(jobName);
        if (jobWithDetails.details().hasFirstBuildRun() && !jobWithDetails.getLastBuild().details().getParameters().isEmpty()) {
            hashMap.putAll(jobWithDetails.getLastSuccessfulBuild().details().getParameters());
        } else {
            // your logic
        }
    } catch (URISyntaxException | IOException e) {
        e.printStackTrace();
    }
    return hashMap;
}
dtrunk90 commented 3 years ago

That's how to get parameters from a build. I would like to get them from the Job itself.

vadipp commented 1 year ago

@dtrunk90 if desperate, you could fetch the job XML and parse it:

String xml = jenkinsServer.getJobXml(jobName)