This Article is about using Jenksins REST API for getting information about the last successful build. Jenkins has no official Java/Kotlin API. This means, that we either have to use some third party Github developers java API, or just to use Jenkins REST API, that is guaranteed to work.

The Problem

I have a Jenkins Instance, on which different jobs are running. I need the git hash of the last successful build for another project.

What can I do? I can go to Jenkins, scroll down to the last successful build of a branch and click on it. The git hash is under Revision and only needs to be copied from there. If you need to do that 20 times a day, it can be pretty nerve wracking. Another usecase for this would be, that you want to automate something that requires the last successful build hash and you can’t put that in manually every time.

The solution

As I said, there are at least two ways to solve this problem. For me, the safety that the solution is reliable and has a big community backing it off, was really important. I decided to not use the unofficial Java API and instead stick with the REST API calls. If the Java API gets official support at the time of the reading, make sure to check that out too.

#rest-api #khttp #jenkins

Jenkins & Khttp | Use REST API to find out the Last Successful Build
1.80 GEEK