2015-10-19 17 views
1

我使用poll-mailbox-trigger-plugin根据传入的电子邮件触发Jenkins作业。解析Jenkins中的HTML

构建参数之一(pmt_content)包含HTML中指定的电子邮件的正文。

是否有Jenkins插件可以解析HTML并检索用户指定标签的值?

邮件内容例如:

<!DOCTYPE html> 
<html> 
<head> 
    <meta content="text/html; charset=UTF-8"> 
    <title></title> 
</head> 
<body style='margin:20px'> 
    <p>The following user has registered a device, click on the link below to 
    review the user and make any changes if necessary.</p> 
    <ul style='list-style-type:none; margin:25px 15px;'> 
     <li><b>User name:</b> Test User</li> 
     <li><b>User email:</b> [email protected]</li> 
     <li><b>Identifier:</b> abc123def132afd1213afas</li> 
     <li><b>Description:</b> Tom's iPad</li> 
     <li><b>Model:</b> iPad 3</li> 
     <li><b>Platform:</b></li> 
     <li><b>App:</b> Test app name</li> 
     <li><b>UserID:</b></li> 
    </ul> 
    <p>Review user: https://cirrus.app47.com/[email protected]</p> 
    <hr style='height=2px; color:#aaa'> 
    <p>We hope you enjoy the app store experience!</p> 
    <p style='font-size:18px; color:#999'>Powered by App47</p><img alt='' src= 
    'https://cirrus.app47.com/notifications/562506219ac25b1033000904/img'> 
</body> 
</html> 

具体来说,我怎么能检索的值 “标识” 标签?

我敢肯定我可以写一个脚本来做到这一点,但我宁愿Jenkins的逻辑。

回答

1

是否有Jenkins插件可以解析HTML并检索用户指定标签的值?

它是一个简单的shell或几行你选择的脚本语言。但看起来,那不是你想要的。

在一般情况下,没有,没有解析HTML和检索标签的价值为目的的插件,请参考https://wiki.jenkins-ci.org/display/JENKINS/Plugins

我怎么能检索的值“标识”标签?

有一个通用插件,称为Conditional BuildStep, 它支持参数的正则表达式。

当HTML邮件内容是pmt_content你可以使用下面的正则表达式

<li><b>Identifier:<\/b>(.*)<\/li>提取值abc123def132afd1213afas(或匹配和exec另一个命令,如果找到)。