6

I'm writing a Jenkins plugin and I want to retrieve last build information (number, timestamp) for a given job from Jenkins api. I can do following REST call and obtain 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 info by calling direct JAVA api instead of this REST call ?

2
  • it seems like it only support remote API, wiki.jenkins-ci.org/display/JENKINS/Remote+access+API. I think it makes more sense as HTTP APIs provides more flexibility :) Commented Feb 7, 2013 at 10:46
  • Thanks Sameera... Yes they are flexible and useful if the message passing is done between two systems. but here it happened within the same system. Means i can directly access Jenkins (Hudson.* packages) from my plugin. No real docs for that :(. Commented Feb 7, 2013 at 10:58

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.