Remote access API

12 views
Skip to first unread message

Jayalakshmi Nair

unread,
May 21, 2020, 7:20:13 AM5/21/20
to Jenkins Developers
Hello all,

I was looking for a lightweight method to get the build details. (As we have a lot of builds and noticed that getBuilds method consumes a lot of time).
I figured out that there is no other approach from the Jenkins methods to get the builds.

Now I am trying to get the build details from $JENKINS_HOME/jobs/$NAME_OF_JOB/api/xml. However ,while trying to read the xml using the url, this throws me a 403 or 401. This can be resolved by authenticating.

Can anyone assist me on how I can obtain the username and password of the currently logged in user in java? Or is there a way to access the job link without authentication?
Or is there any api in java which helps me read the above URL?

Thanks in advance.

-Jayalakshmi

Matt Sicker

unread,
May 21, 2020, 10:49:35 AM5/21/20
to jenkin...@googlegroups.com
You need to create an API token in your user account to authenticate.
> --
> You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-de...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/e4cb9ec0-5bb8-4014-bb3a-428aab6d7ccc%40googlegroups.com.



--
Matt Sicker
Senior Software Engineer, CloudBees

Markus Winter

unread,
May 23, 2020, 7:24:14 AM5/23/20
to jenkin...@googlegroups.com
I doubt that using the REST api is faster. Under the hood the getBuilds method is also called. But additionally you have to convert the result to XML, transfer the xml and read it back in.

It is not possible to get the password of any user. That would be a big security issue if this would be possible.

It seems to try to get the build details from within your Jenkins instance (via system groovy?). Maybe you describe what you want to achieve.
You could also loop yourself from the last build and use the getPreviousBuild
or use getBuilds(RangeSet)

martinda

unread,
May 23, 2020, 3:11:58 PM5/23/20
to Jenkins Developers

Or is there any api in java which helps me read the above URL?

I have used this library quite successfully: https://github.com/cdancy/jenkins-rest
But you still have to provide the credentials.

Martin 
Reply all
Reply to author
Forward
0 new messages