Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No way to get the job parameters? #470

Open
dtrunk90 opened this issue Sep 3, 2020 · 3 comments
Open

No way to get the job parameters? #470

dtrunk90 opened this issue Sep 3, 2020 · 3 comments

Comments

@dtrunk90
Copy link

dtrunk90 commented Sep 3, 2020

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

@vikas981
Copy link

vikas981 commented Oct 10, 2020

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
Copy link
Author

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

@vadipp
Copy link

vadipp commented Dec 6, 2022

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

String xml = jenkinsServer.getJobXml(jobName)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants