jenkinsci / java-client-api

A Jenkins API client for Java
MIT License
901 stars 470 forks source link

[Query] I am not able to set password parameters with job.build(params) #415

Open krzysztofreczek opened 5 years ago

krzysztofreczek commented 5 years ago

Hi All,

Looks like I am not able to set password parameters when triggering job builds.

My code looks more or less like this:

Map<String, String> params = new HashMap<>();
params.put("USERNAME", "plain-text-username");
params.put("PASSWORD", "secret-password");

jenkins.getJob("job-name").build(params);

As the USERNAME is a generic StringParameter input it is passed properly to the build, while PASSWORD a PasswordParameter type input is not set at all.

I could see in the code all of the parameters are passed as BuildWithParameters&... URL inlined arguments which most likely block passwords. For my own scripting purposes, I use JSON payload which works with all types of inputs.

Is this possible to pass passwords with the current approach? Am I missing something here? If the issue is valid, would you consider a change of a method of passing arguments into JSON payload? I would love to contribute.

khmarbaise commented 5 years ago

Hi, usually you set credentials during the initial creation of the Jenkins instance like:

JenkinsServer jenkins = new JenkinsSefver ("...", "username", "password");
...
krzysztofreczek commented 5 years ago

Hi Karl, thanks for your response.

Your example is obvious of course but I was referring to a bit different use-case.

Please note that pretty often you may want to parameterize your jobs with secret parameters. Sometimes you may want to pass some secrets, tokens, etc to the job and use it during the course of the build. Then, to secure it correctly you use Password Parameter which comes with value masking and so on. This kind of parameters cannot be passed as URL inlined argument. I am pretty sure this may apply to multi-line string parameters as well.

kumarshorav11 commented 4 years ago

@khmarbaise I am using same way to get a jenkins server. However, When I am trying to create a JOB, it is showing unauthorized error even though providing correct user name and password. Then I changed the security configuration of my Jenkin server, - "any user can do any thing". then I am able to create a job. Again I reset to previous configuration of Jenkin, I noticed that through Java call, it is logging in to Jenkin server as Anonymous server, even though the provided user name and password have authority to create job and any such power. What else I can do, so that I would be able to connect to Jenkins server where "logged in user can do any thing ".