Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/jenkins/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Email 在Jelly模板中读取和解析外部XML文件_Email_Jenkins_Jelly - Fatal编程技术网

Email 在Jelly模板中读取和解析外部XML文件

Email 在Jelly模板中读取和解析外部XML文件,email,jenkins,jelly,Email,Jenkins,Jelly,我用的是詹金斯1.410和电子邮件分机2.14。我的项目是一个健全的检查,以验证许多其他构建,确保它们的工件被正确交付,然后发送一封摘要电子邮件。没关系 现在,我试图解析父项目的POM.xml并提取一组依赖版本,并将它们包含在电子邮件中格式良好的部分中 问题:在Jelly模板中,如何读取外部pom.xml(将其作为行、xml dom对象、大字符串等的集合/数组获取)并提取所需的属性/属性。考虑到这一点,我可以将它们格式化成表格或类似的东西 我需要创建自己的插件吗(这对我来说是新的)?或者该功能是

我用的是詹金斯1.410和电子邮件分机2.14。我的项目是一个健全的检查,以验证许多其他构建,确保它们的工件被正确交付,然后发送一封摘要电子邮件。没关系

现在,我试图解析父项目的POM.xml并提取一组依赖版本,并将它们包含在电子邮件中格式良好的部分中

问题:在Jelly模板中,如何读取外部pom.xml(将其作为行、xml dom对象、大字符串等的集合/数组获取)并提取所需的属性/属性。考虑到这一点,我可以将它们格式化成表格或类似的东西

我需要创建自己的插件吗(这对我来说是新的)?或者该功能是否已经存在


非常感谢。

此功能已存在于Email ext插件中。您可以使用XML标记库从该插件中配置的Jelly脚本读取XML文件:

下面是一个如何解析jenkins作业工作区中的pom.xml文件的示例。一旦文件被读取到{myxmldoc},它就成为一个dom4j文档,可以与标准XPATH表达式一起使用,查询或循环所需的属性和元素:

<j:set var="WORK_SPACE" value="${buildenv.get('WORKSPACE')}"/>
<x:parse xml="${WORK_SPACE}/pom.xml" var="myxmldoc"/> 

<!--select element with particular attribute-->
<x:set var="myvar" select="$myxmldoc/project/build/plugins/plugin[@attribute='abc']"/>

<!--Loop through elements-->
<x:forEach var="myloopvar" select="$myxmldoc/project/build/plugins/plugin">
.....
</x:forEach>

.....

预步骤

1. Download common-jelly package from: http://redrockdigimark.com/apachemirror/commons/jelly/binaries/commons-jelly-1.0.zip
2. Extract the files from the zip
3. Copy the following files: commons-jelly-tags-util-1.1.1.jar, commons-jelly-tags-xml-1.1.jar, commons-jelly-tags-fmt-1.0.jar
4. Paste the above files at: <Jenkins server path>\war\WEB-INF\lib
5. Restart Jenkins
1。从以下站点下载common jelly软件包:http://redrockdigimark.com/apachemirror/commons/jelly/binaries/commons-jelly-1.0.zip
2.从zip文件中提取文件
3.复制以下文件:commons-jelly-tags-util-1.1.jar、commons-jelly-tags-xml-1.1.jar、commons-jelly-tags-fmt-1.0.jar
4.将上述文件粘贴到:\war\WEB-INF\lib
5.重新启动詹金斯
XML是:abc.XML

<sites>
 <site>
  <URL>http://www.google.com</URL>
  <STATUS>200</STATUS>
 </site>
 <site>
  <URL>http://www.yahoo.com</URL>
  <STATUS>200</STATUS>
 </site>
</sites>

http://www.google.com
200
http://www.yahoo.com
200
读取上述XML的果冻代码

<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form" xmlns:x="jelly:xml" xmlns:html="jelly:html" xmlns:util="jelly:util">

<j:set var="xmlFilePath" value="${build.getWorkspace().child('abc.xml')}"/>
<util:file name="${xmlFilePath}" var="xmlFileContent" />
<x:parse var="myxmldoc" xml="${xmlFileContent}"/>
<x:set var="allSites" select="$myxmldoc/sites"/>
<table class="border">
 <tr>
  <th class="border1"><b>URL</b></th>
  <th class="border1" width="140px"><b>HTTP Code</b></th>
  <th class="border1" width="140px"><b>Status</b></th>
 </tr>
 <x:forEach var="mysite" select="$allSites/site">
 <j:set var="myURL"><x:expr select='$mysite/URL' /></j:set>
 <j:set var="myStatus"><x:expr select='$mysite/STATUS' /></j:set>
 <tr>
  <td class="border_test_passed">
   <a href="${myURL}">${myURL}</a>
  </td>
  <td class="border_test_total">
   <b>${myStatus}</b>
  </td>
  <td class="border_test_total">
   <j:choose>
    <j:when test="${myStatus=='200'}"><img src="${rooturl}userContent/BSGreen.png" width="15px" /></j:when>
    <j:otherwise><img src="${rooturl}userContent/BSRed.png" width="15px" /></j:otherwise>
   </j:choose>
  </td>                     
 </tr>
 </x:forEach>
</table>

统一资源定位地址
返回码
地位
${myStatus}