Search code examples
automationhudsonhudson-pluginshudson-api

Get last successfull build on Hudson


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.


Solution

  • 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.