Get build information from the Jenkins API

I am writing a Jenkins plugin and I want to get the latest build information (number, timestamp) for jobs from the Jenkins api. I can make the next REST call and get it.

<url_to_jenkins>job/<job name>/api/json?tree=builds[number,status,timestamp,id,result]

Since my plugin is also deployed inside Jenkins, is there a way to get this information by calling the direct JAVA api instead of this REST call?

+5
source share
2 answers

Jenkins java docs are available here . These apis can also be used with groovy script directly. If you want to use the Postbuild groovy script plugin, you can access the assembly with manager. The following is an example code snippet that disables an assembly if it is unsuccessful.

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

Groovy Postbuild

+2

java- :
1) : Jenkins.getInstance(). GetItem ( "jobName" )
2) , ( ) 3), .getLastBuild()
4) (AbstractBuild), , , ..

0

All Articles