views:

38

answers:

1

I need to filter the build results of a job based on the description of the build in Hudson. I found a plugin that allows for filtering based on the job description, however I'm not sure how I would begin to do the same for builds.

+1  A: 

Use Hudsons XML API with XPATH

http://&lt;your hudson url>/api/xml?depth=1&xpath=//job/description[contains(./text(),'<search string>')]&wrapper=jobs

will show you the descriptions of all jobs that contain the given search string

with some more xpath magic you can probably get it to display the result of the latest build also (the path is job/lastBuild/result , possibly you need to increase the depth to 2)

consult the xml api at http://&lt;your hudson url>/api for further reference

Edit:

http://&lt;your hudson url>/api/xml?depth=2&xpath=child::hudson/job[contains(displayName,'<search string>')]/*[self::name or self::lastBuild]&wrapper=jobs

almost works for me, it shows the name and the last build, but unfortunately in a structure like this

<jobs>
    <name>job1</name>
    <lastBuild>
        <!-- snip a lot -->
        <result>SUCCESS</result>
        <!-- snip a lot -->
    </lastBuild>
    <name>job2</name>
    <lastBuild>
        <!-- snip a lot -->
        <result>SUCCESS</result>
        <!-- snip a lot -->
    </lastBuild>
</jobs>

whereas I'd prefer this:

<jobs>
    <job>
        <name>job1</name>
        <lastBuild>
            <!-- snip a lot -->
            <result>SUCCESS</result>
            <!-- snip a lot -->
        </lastBuild>
    </job>
    <job>
        <name>job2</name>
        <lastBuild>
            <!-- snip a lot -->
            <result>SUCCESS</result>
            <!-- snip a lot -->
        </lastBuild>
    </job>
</jobs>

can somebody provide the necessary xpath fine-tuning?


EDIT again

now I realized you want to read info about builds, not jobs, so use this code instead:

http://&lt;your hudson url>/job/<your job name>/api/xml?depth=1&xpath=//build[contains(action/cause/shortDescription,'<search string>')]/*[self::result or self::number]&wrapper=builds
seanizer