XPath 和 Jenkins Plot 插件

发布于 2024-12-28 05:11:58 字数 1285 浏览 3 评论 0原文

我正在尝试使用 Jenkins 的 Plot 插件生成一个图表,显示我们的代码中有多少个“TODO”标记。

我在构建过程中生成了一个 XML 文件,其中包含有关它们的数据(除其他外):每个 TODO 标记在 XML 中都有一行,如下所示:

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

使用独立的 xpath 工具,我可以使用表达式//tag[@name='todo'] 获取所有匹配的元素,或 count(//tag[@name='todo']) 获取他们的数量。

这个计数是我想要绘制的值。但是我无法将任何数据添加到詹金斯的图表中。

我已经创建了绘图并指定它是一个 XML 文件。然后 Jenkins 询问我结果是否是节点集、节点、字符串、布尔值或数字。

我假设“Nodeset”适用于 //tag[@name='todo'] 和“Number”适用于 count(//tag[@name='todo'])< /代码>。但我已经尝试过它们,它们都只给了我一个空图表,上面没有绘制任何数据。

最令人沮丧的是 Jenkins 没有给我任何关于问题所在的反馈;只是空图。构建日志中或我能看到的其他任何地方都没有任何内容。

谁能帮我让它工作吗?我在任何地方都找不到任何例子。看起来应该很简单,但这对我来说却没有发生。

提前致谢。

[编辑]

XML 的更大样本,如评论中所要求的:(

<?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>

我已经剪掉了不相关的元素和属性,但这是基本结构)

据我所知,没有那里发生的任何 XML 命名空间。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

横笛休吹塞上声 2025-01-04 05:11:58

我最终完成的工作如下:

我生成一个包含以下数据的报告文件:

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

然后我使用以下配置配置我的绘图:

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

然后我得到了正确的数据绘图:系列名称取自元素名称(serie1, serie2...) 并且该值取自文本内容。
事实上,这就是帮助块中的解释:

 (...)
 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. 

我不认为这个插件能够从 XML 属性中获取值。也许您应该考虑编写一个简单的 XSLT 样式表,它将您的文件转换为具有预期格式的另一个文件。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文