简体   繁体   中英

XPath and Jenkins Plot plugin

I'm trying to use Jenkins' Plot plugin to generate a graph of how many "TODO" markers we have in our code.

I have an XML file being generated as part of the build which includes data about them (among other things): each TODO marker has a line in the XML which looks like this:

<tag line="3" name="todo" description="Do something with this"/>

Using a stand-alone xpath tool, I can use an expression //tag[@name='todo'] to get all the matching elements, or count(//tag[@name='todo']) to just get the number of them.

This count is the value I want to plot. However I've been unable to get any data onto a chart in Jenkins.

I've created the plot and specified that it's an XML file. Jenkins then asks me if the result will be a Nodeset, Node, String, Boolean or Number.

I assume "Nodeset" would be applicable to //tag[@name='todo'] and "Number" to count(//tag[@name='todo']) . But I've tried them both, and both of them just give me an empty graph, with no data plotted on it.

The most frustrating thing of all is that Jenkins doesn't give me any feedback on what the problem is; just the empty graph. Nothing in the build log, or anywhere else I can see.

Can anyone help me get this working? I can't find any examples anywhere. It seems like it ought to be simple, but it's just not happening for me.

Thanks in advance.

[EDIT]

A larger sample of the XML, as requested in the comments:

<?xml version="1.0" encoding="utf-8"?>
<project>
  <method>
    <docblock>
      <tag line="763" name="todo" description="This needs doing"/>
    </docblock>
  </method>
  <method>
    <docblock>
      <tag line="14" name="todo" description="This also needs doing"/>
    </docblock>
  </method>
</project>

(I've snipped out elements and attributes that aren't relevant, but this is the basic structure)

So as far as I can tell, there isn't any XML namespacing going on there.

What I finally achieved to make work is the following :

I generate a report file with the following datas :

<report>
  <serie1>10</serie1>
  <serie2>20</serie2>
  <serie3>30</serie3>
</report>

Then I configure my plot with the following configuration :

 XPath Result type : Nodeset
 XPath Expression : /report/*

Then I get a correct plotting of my datum : the series names are taken from the element name (serie1, serie2...) and the value is taken from the text content. Indeed, this is what was explained in the help block :

 (...)
 If a nodeset is selected, a point for each node that is selected will be plotted.
 The label of each point is the name of the element that was selected, the value is the text value. 

I don't think that this plugin is capable of taking values from XML attributes. Maybe you should consider writing a simple XSLT stylesheet which will transform your file to another one with the expected format.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM