Get build information from Jenkins API Get build information from Jenkins API jenkins jenkins

Get build information from Jenkins API


Jenkins java docs are available here. These apis can also be used along with groovy script directly. If you want to use Postbuild groovy script plugin, you can access the build with manager. Below is a sample code snippet which disables a build if it is unsuccessful

if (manager.build.result.isWorseThan(hudson.model.Result.SUCCESS)) {manager.build.project.disabled = true}

You can have look at Groovy Postbuild Plugin for more details


From java code it should looks like:
1) get item: Jenkins.getInstance().getItem("jobName")
2) check that item is instanceof some job type (or just Abtract) and cast
3) then just call .getLastBuild() on this object
4) this will be a build object (AbstractBuild) where you can get id, date, result and etc.