3

I was wondering if anyone know of a way or a plug in to get the last build version with result of success from a particular Hudson job using the CLI somehow.

I can see this result is held in the [DateTime]\build.xml file so I could write something to grab the result but was wondering if anyone has done this already or a know of a way to use the CLI to grab this information?

I have tried to find the information on the documentation but was unable to find the answer. If you need anymore detail then let me know.

AdrieanKhisbe
  • 3,899
  • 8
  • 37
  • 45
Rubans
  • 4,188
  • 6
  • 40
  • 58

3 Answers3

7

I'm a bit late to the party here, but you can also just use the URL http://localhost:8081/job/jobname/lastSuccessfulBuild to get the last successful build. If you want to extract specific data from that page you can use http://localhost:8081/job/jobname/lastSuccessfulBuild//api

gareth_bowles
  • 20,760
  • 5
  • 52
  • 82
2

You can do it with XPATH:

http://localhost:8081/api/xml?depth=2&xpath=/hudson/job/name[text()="JReport2"]/../build/result[text()="SUCCESS"]/../../build[1]/number/text()

In the above example I'm getting the last successful build number of the build named JReport2. You can query your Hudson server via WGET or CURL sending it an HTTP GET that is equivalent to that URI.

The XPath expression can be shortened, but in the long form it is easier to understand what's going on.

In general, it is instructive to enter http://<hudson-server>/api/xml in your browser and examine the output.

malenkiy_scot
  • 16,415
  • 6
  • 64
  • 87
  • Excellent, thanks that sort of works but the URL provided in the example didn't work properly since it didn't return the last successful build, only the last build. However thanks to the API you referred to, I was able to use "http://[myserver]/job/[jobname]/lastSuccessfulBuild/api/xml?xpath=/*/description/text()" – Rubans Jun 22 '12 at 15:41
  • Good idea! Thanks for mentioning that it's buggy - I'll try to debug it. – malenkiy_scot Jun 22 '12 at 16:26
1

Correct xpath is as:

...&xpath=/hudson/job/name[text()="...name of project..."]/../build/result[text()='SUCCESS']/../number/text()

but it is not work.

Working xpath is as:

http://HudsonServer:Port/job/..nameOfProject../lastSuccessfulBuild/api/xml?xpath=//number/text()

As described above:

...&xpath=/hudson/job/name[text()="JReport2"]/../build/result[text()="SUCCESS"]/../../build[1]/number/text()

it is not correct xpath because /../../build[1]/number/text() always gives the first build.

Alex Quick
  • 11
  • 3