1

I am trying to find out the details of a build through API. I am using below to get the specific result. http://localhost:8080/job/test/lastBuild/api/json?pretty=true

Now when the build is failed, I am just getting the status of the build. I want to determine which build step is causing the problem. Please let me know how can I get it through api

Erik Philips
  • 53,428
  • 11
  • 128
  • 150
user987709
  • 13
  • 1
  • 4

2 Answers2

2

I have been doing some work on scraping the failed builds out of our Jenkins instance, and then trying to match up failures, including ones categorized by the Build Failure Analyzer, and I can tell you it is a bit frustrating.

We have three types of builds (FreeStyle, Matrix, and Workflow) and each of them reports things differently. Tim's comment bout using depth=3 on the API works, but I have been using the more specific:

https://HOST_NAME/job/PROJECT_NAME/api/json?pretty=true&tree=allBuilds[number,timestamp,url,duration,result,runs[url,number],actions[foundFailureCauses[*]]]

The tree part makes better sure you get all the parts you want (sometimes the depth does not get thing that this does), as well as excluding things you don't. This works for FreeStyle builds, and Workflow builds that terminate with a single node.

For Matrix builds you then have to follow the links provided in runs, but you have to munch the URL it gives you (it puts the build number in the wrong place). Then you call the same API on the linked build to scrape out that one.

For Workflow builds there is annoying news, good news, bad news, and even worse news as far as I know. The annyoying part is that you have to see that this is a Workflow build (look at the _class property that you got without asking for it), and then look at the build url, but replacing wfapi for api/json (and forgetting the rest of the parameters). Then you can follow the json links that you get back form that to locate the failures. The good news is that this gives you a much better link to the failure, including intelligible messages (sometime).

The bad news is that I am not sure that the Build Failure Analyzer is working properly for these, or knows how to mark it on the proper build step.

The even worse news is that for a lot of builds on my server this API does not seem to work at all. This is even though I can see similar information through the BlueOcean UI. I am investigating running this down now.

Sorry that this is not a simple answer, but that is the state of things as far as I can tell at this point.

larkost
  • 89
  • 3
1

This is a interesting question.

I never found something like this before, since Jenkins just tell you good or bad as you said.

A possible solution would be using the Jenkins BFA plugin.

https://wiki.jenkins-ci.org/display/JENKINS/Build+Failure+Analyzer

This plugin can help you auto detect the error based on the error pattern you described in the config.

And then you can collect the detail error info from the jenkins json file.

Br,

Tim

Tim
  • 2,006
  • 2
  • 18
  • 25
  • I have installed the BFA plug in and configure the failure pattern. But can you please point me how to get this error in jenkins api json format. – user987709 Aug 01 '16 at 23:40
  • Hi, you need use something like this https://localhost/jenkins/job/ShellTest/1/api/json?pretty=true&depth=3 , depth=3 will help you show the failure cause related info, a example would be "foundFailureCauses" : [ { "categories" : [ "Pom" ], "description" : "scm connection or developerConnection must be specified", "id" : "28953504-e351-4dff-9c9b-1143325d6c7a", "name" : "Pom - Missing SCM Information" }, then you can just parse the response with any json parser. – Tim Aug 02 '16 at 07:28