[email-ext plugin] it failed to get instances of the class CucumberTestResultAction in groovy email template

72 views
Skip to first unread message

Oxygen

unread,
Feb 14, 2022, 1:31:17 AM2/14/22
to Jenkins Users
I need to write a groovy email template to send HTML email in a Jenkins job, I copied the following example and made some changes, https://github.com/jenkinsci/email-ext-plugin/blob/master/src/main/resources/hudson/plugins/emailext/templates/groovy-html.template

I found that the following call returns null even if the job has the the plugin "Cucumber reports" configured in post-build actions

 it.getAction("org.jenkinsci.plugins.cucumber.jsontestsupport.CucumberTestResultAction")
it threw the following exception:
Exception raised during template rendering: Cannot invoke method getResult() on null object
        java.lang.NullPointerException: Cannot invoke method getResult() on null object
        at org.codehaus.groovy.runtime.NullObject.invokeMethod(NullObject.java:91)
        at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:48)
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
        at org.codehaus.groovy.runtime.callsite.NullCallSite.call(NullCallSite.java:35)
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117)
        at SimpleTemplateScript36.run(SimpleTemplateScript36.groovy:5)
        at groovy.text.SimpleTemplateEngine$SimpleTemplate$1.writeTo(SimpleTemplateEngine.java:168)
        at groovy.text.SimpleTemplateEngine$SimpleTemplate$1.toString(SimpleTemplateEngine.java:180) 


How can I get the actual Cucumber test results in groovy template? by the way what is the predefined variable it in the template, what's the class type of it, I am curious about it.

the groovy template is as follows:
<BODY>
  <%
  def featureResults=[]
  def cucumberTestResultAction = it.getAction("org.jenkinsci.plugins.cucumber.jsontestsupport.CucumberTestResultAction")
  featureResults=cucumberTestResultAction.getResult()
  def fail_test=0
  def passed_test=0
  def skip_test=0
  def total_tests=0
  featureResults.each {
  fResult ->
      fail_test=fail_test+fResult.getFailCount()
      passed_test=passed_test+fResult.getPassCount()
      skip_test=skip_test+fResult.getSkipCount()
  }
  total_tests=fail_test+passed_test+skip_test
 %>
</BODY>


the job is configured with the plugin Cucumber reports for generating Cucumber test report, but it doesn't use cucumber-plugin, it runs tests with gradle command line.

Thanks

James Nord

unread,
Feb 17, 2022, 12:54:01 PM2/17/22
to Jenkins Users
cucumber-reports does not contain  CucumberTestResultAction so the action will never be added by it which is the main issue you have.

CucumberTestResultAction is provided by the cucumber-testresult plugin cucmber-reports as far as I am aware does (at least did not) not provide a model you can inteorogate or otherwise integrate with Jenkins and is a mostly dumb publisher around converted HTML.

/James

Reply all
Reply to author
Forward
0 new messages