I have used Jenkins REST API URL to get build status using Java (JAR). It is working successfully by passing user name and password to the API URL. I created a job in Jenkins and using that JAR file to get build status. But, my question is that why should the credential be passed again to API URL as I already logged-in in Jenkins to access the job? The API URL should be accessible without credentials. How to achieve the same?
Asked
Active
Viewed 321 times
1 Answers
0
REST does not persist any session information:
Relevant session data is sent to the receiver by the client in such a way that every packet of information transferred can be understood in isolation, without context information from previous packets in the session.
From https://en.wikipedia.org/wiki/Representational_state_transfer#Statelessness
That means, you must send the credentials with every call by design.
You can have a look at the Java API Client for Jenkins, but it uses the REST API under the hood as well I assume: https://github.com/jenkinsci/java-client-api

Meiswjn
- 752
- 6
- 17
-
Thank you. For testing I hard coded username and password in java to call API URL. But for production, I need to get the logged-in user's password to pass. Planned to add a password parameter for the user to manually enter their password, but I have more than 100 project and need to configure in all. It's a time consuming task. any other method to achieve it. – Jayakumari Arumugham May 03 '22 at 08:42
-
What is the usecase exactly? – Meiswjn May 03 '22 at 08:55
-
I created 100+ parameterized freestyle jobs in Jenkins & maintaining a single ANT build XML file for release process & working effectively in prod.I need to get previous build details & use in current build.For that,I am calling Jenkins API in java to get details by passing specific job name,build number,username and password & using JAR in ANT build.It is one time process & not required to change in 100+ job.But for password,it is required to touch all jobs' configuration it seems as I hard coded password in Java.I am trying to incorporate new requirement without disturbing current process. – Jayakumari Arumugham May 03 '22 at 10:01
-
Perhaps this helps: https://stackoverflow.com/questions/40284904/get-previous-build-result – Meiswjn May 03 '22 at 12:24