首页 > 解决方案 > 常规错误 MissingPropertyException 没有这样的属性:类的结果:hudson.model.CauseAction

问题描述

我们使用 mail-ext 和机器人框架来尝试在 jenkins 中格式化所有测试套件的详细信息,并发送报告。

这是我们现在使用的 groovy 电子邮件模板,它是从 github 下载的,https://github.com/JMcn/jenkins-email-ext-templates/blob/master/robot.groovy

但是这个模板报告了下面的异常,我没有通过谷歌搜索得到类似的错误,我们错过了这个模板的任何东西,感谢任何关于这个错误的提示。

<%
import java.text.DateFormat
import java.text.SimpleDateFormat
%>

........

<!-- System Test Result -->
<%
    def robotResults = false
    def actions = build.actions // List<hudson.model.Action>
    def robotTestResultAction = it.getAction("hudson.plugins.robot.RobotBuildAction")
    actions.each() { action ->
    if( robotTestResultAction != null ) {
    //if( action && (action.class.simpleName.equals("RobotBuildAction") ) ) {
        robotResults = true
%>
<TABLE width="100%">
    <TR><TD class="bg1" colspan="4"><B>test results</B></TD></TR>
    <TR style="border:1px solid #000;height:25px">
        <TD>total</TD>
        <TD>passed</TD>
        <TD>failure</TD>
        <TD>passrate</TD></TR>
    <TR style="border:1px solid #000;height:25px">
        <TD>${robotTestResultAction.getTotalCount()}</TD>
        <TD style="color:green"><%=robotTestResultAction.getTotalCount() - robotTestResultAction.getFailCount()%></TD>
        <TD style="color:red"><a style="color:red" href="${rooturl}${build.url}/${robotTestResultAction.urlName}">${robotTestResultAction.getFailCount()}</a></TD>
        <TD>${robotTestResultAction.overallPassPercentage}%</TD></TR>
</TABLE>

<TABLE cellspacing="0" cellpadding="4" border="1" align="center">
<thead>
   <tr bgcolor="#F3F3F3">
      <td><b>test case name </b></td>
      <td><b>state</b></td>
      <td><b>execute duration</b></td>
   </tr>
</thead>
<tbody>
<%  def suites = action.result.allSuites
    suites.each() { suite ->
      def currSuite = suite
      def suiteName = currSuite.displayName
      // ignore top 2 elements in the structure as they are placeholders
      while (currSuite.parent != null && currSuite.parent.parent != null) {
        currSuite = currSuite.parent
        suiteName = currSuite.displayName + "." + suiteName
      } %>
<tr><td colspan="3"><b><%= suiteName %></b></td></tr>
<%    DateFormat format = new SimpleDateFormat("yyyyMMdd HH:mm:ss.SS")
      def execDateTcPairs = []
      suite.caseResults.each() { tc ->
        Date execDate = format.parse(tc.starttime)
        execDateTcPairs << [execDate, tc]


             }
      // primary sort execDate, secondary displayName
      execDateTcPairs = execDateTcPairs.sort{ a,b -> a[1].displayName <=> b[1].displayName }
      execDateTcPairs = execDateTcPairs.sort{ a,b -> a[0] <=> b[0] }
      execDateTcPairs.each() {
        def execDate = it[0]
        def tc = it[1]  %>
<tr>
  <td><%= tc.displayName %></td>
  <td style="color: <%= tc.isPassed() ? "#66CC00" : "#FF3333" %>"><%= tc.isPassed() ? "PASS" : "FAIL" %></td>
  <td><%= execDate %></td>
</tr>
<%    } // tests
    } // suites %>
</tbody>
</TABLE>
<%
  } // robot results
}
if (!robotResults) {
%>
<TABLE width="100%">
    <TR><TD class="bg1" colspan="2"><B>接口测试结果</B></TD></TR>
    <TR><TD colspan="2">robotTestResultAction is null</TD></TR>
</TABLE>
<%
    }
%>
<BR/>

模板呈现期间引发异常:没有这样的属性:类的结果:hudson.model.CauseAction groovy.lang.MissingPropertyException:没有这样的属性:类的结果:org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap 的 hudson.model.CauseAction (ScriptBytecodeAdapter.java:53) 在 org.codehaus.groovy.runtime.callsite.GetEffectivePojoPropertySite.getProperty(GetEffectivePojoPropertySite.java:66) 在 org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGetProperty(AbstractCallSite.java:296) 在

使用 Krzysztof Błażełek 的建议调整脚本后,我们收到以下错误。

<!-- System Test Result -->
<%
    def robotResults = false
    def actions = build.actions // List<hudson.model.Action>
    //def robotTestResultAction = it.getAction("hudson.plugins.robot.RobotBuildAction")
    actions.each() { action ->
    //if( robotTestResultAction != null ) {
    if( action && (action.class.simpleName.equals("RobotBuildAction") ) ) {
        robotResults = true

模板呈现期间引发异常:无法在空对象 java.lang.NullPointerException 上获取属性“simpleName”:无法在 org.codehaus.groovy.runtime.NullObject.getProperty(NullObject.java:60) 处获取空对象上的属性“simpleName” org.codehaus.groovy.runtime.InvokerHelper.getProperty(InvokerHelper.java:174) 在 org.codehaus.groovy.runtime.callsite.NullCallSite.getProperty(NullCallSite.java:47) 在 org.codehaus.groovy.runtime.callsite。 AbstractCallSite.callGetProperty(AbstractCallSite.java:296) 在 SimpleTemplateScript211$_run_closure6.doCall(SimpleTemplateScript211.groovy:403) 在 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ....

标签: jenkinsgroovy

解决方案


您已经修改了您提供的模板,这导致了问题。我相信您正在迭代所有操作(不仅仅是hudson.plugins.robot.RobotBuildAction),这导致了异常。尝试更改此部分:

<!-- System Test Result -->
<%
    def robotResults = false
    def actions = build.actions // List<hudson.model.Action>
    def robotTestResultAction = it.getAction("hudson.plugins.robot.RobotBuildAction")
    actions.each() { action ->
    if( robotTestResultAction != null ) {
    //if( action && (action.class.simpleName.equals("RobotBuildAction") ) ) {
        robotResults = true
%>

进入

<!-- System Test Result -->
<%
    def robotResults = false
    def actions = build.actions // List<hudson.model.Action>
    actions.each() { action ->
    if( action && (action.class.simpleName.equals("RobotBuildAction") ) ) {
        robotResults = true
        def robotTestResultAction = action
%>

您的代码需要重构,但这是测试它是否有效的最快方法。


推荐阅读