jenkinsci / jenkinsci/java-client-api

HttpResponseException: Forbidden while trying to call create job in jenkins through java

Open
#432 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
913
Forks
466
PR merge metrics
No merged PRs in 30d

Description

I am using below code to connect to Jenkin server.

```
JenkinsServer jServer = new JenkinsServer(new URI(JENKINS_URL), JENKINS_USER_NAME, JENKINS_PASSWORD);
Map jobs = jServer.getJobs();

jobs.forEach((k, v) -> {
System.out.println("Job -> " + k.toString());
});

JobWithDetails job = jobs.get(JENKINS_JOB_NAME).details();
job.getBuilds().forEach(b -> System.out.println("Build Details : " + b.getNumber()));
```
I am able to list all the jobs available on the server. However, when I am trying to create a Job by calling .createJob() method by passing job name and config.xml, I am getting the above exception.
Then, what I did , I changed Jenkin configuration and opted for "Any User can do any thing" option. After this, I am able to create the job. I also observed that When I am giving correct credentials as shown in the above code, java call still logging as anonymous user and hence not able to create a job.
I also tried using TOKEN to authenticate to jenkins server but no help.
So, how to create job using this api without changing to Jenkin security. It should work within "Logged in user can do any thing" in Jenkin security option.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.