XPath plugin and Jenkins Plot

I am trying to use the Jenkins Plot plugin to plot how many TODO markers we have in our code.

I have an XML file that is created as part of an assembly that includes data about them (among other things): each TODO token has a line in XML that looks like this:

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

Using the standalone xpath tool, I can use the expression //tag[@name='todo'] to get all the matching elements or count(//tag[@name='todo']) to just get their number.

This counter is the value I want to build. However, I could not get the data on the chart in Jenkins.

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

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

The most unpleasant of all is that Jenkins does not give me any feedback on what the problem is; just an empty graph. Nothing in the build log or anywhere else I see.

Can someone help me get this job? I cannot find examples anywhere. It seems like it should be simple, but it just is not for me.

Thanks in advance.

[EDIT]

Larger XML sample as indicated 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 cut out elements and attributes that are not relevant, but this is the main structure)

So, as far as I can tell, there is no XML namespace there.

+4
source share
1 answer

What I finally achieved to do the job is the following:

I create a report file with the following data:

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

Then I set up my schedule with the following configuration:

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

Then I get the correct construction of my binding: the series names are taken from the element name (serie1, serie2 ...), and the value is taken from the text content. In fact, this is 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 do not think that this plugin is able to accept values โ€‹โ€‹from XML attributes. Perhaps you should consider writing a simple XSLT stylesheet that converts your file to another with the expected format.

+4
source

Source: https://habr.com/ru/post/1392034/


All Articles