is there a way to see all the available methods of a plugin in Jenkins?

40 views
Skip to first unread message

jesus fernandez

unread,
Apr 9, 2021, 7:08:25 AM4/9/21
to Jenkins Users
I am learning Jenkins on my own and I am trying to learn about plugins. I have a stage to send an email with the cppcheck results with a template I found https://stackoverflow.com/questions/13888338/sending-cppcheck-result-report-on-email-from-jenkins-using-email-ext-plugin the template instantiate the ```CppcheckBuildAction``` and access its methods, what I would like to know if is possible to check what methods are avaialable for that instance and if possible how / where I can see them.
Also how could I for example echo / println one of them. For instance in the template provided in the link above it acces the total number of errors with ${cppcheckResult.report.getNumberTotal()} but if I echo it I get an error ```groovy.lang.MissingPropertyException: No such property: cppcheckResult for class: groovy.lang.Binding```, this is what I tried
stage('Email') {
steps {
script{
publishCppcheck pattern:'cppcheck.xml'
emailext( subject: 'foo', to: 'ma...@mail.net', body: '${JELLY_SCRIPT, template="custom"}')
}
echo "${cppcheckResult.report.getNumberTotal()}"
}
}
my final goal actually is to send the email just when the report find a new error so I was thinking to save the total number of errors in an external file and compare it with each build and if the number is bigger send the email, is there any native / easier way to do this?

Ullrich Hafner

unread,
Apr 9, 2021, 7:48:03 AM4/9/21
to Jenkins Users
You need to read the code of the plugin. I.e., the model of the producer plugin.


--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/901e41a0-e2ec-466c-87a9-23d6082897e1n%40googlegroups.com.

jesus fernandez

unread,
Apr 9, 2021, 7:58:10 AM4/9/21
to Jenkins Users
Thanks for asering. I have been checking the javadoc of the plugin https://javadoc.jenkins.io/plugin/email-ext/ but my java knowledge is super basic and I do not get to see where the methods available to Jenkins are. So I guess this is too advanced for me ATM

Ullrich Hafner

unread,
Apr 9, 2021, 8:27:16 AM4/9/21
to Jenkins Users
Are your projects located in GitHub? Then it would be quite easy to report results automatically using the GitHub checks plugin. Email is quite old-school when it comes to build result reporting... 

jesus fernandez

unread,
Apr 9, 2021, 8:32:47 AM4/9/21
to Jenkins Users
my projects are in Perforce. What if I want to acces to one of those properties which I know are available from looking at the jelly template, for instance ${cppcheckResult.getDiff().getNumberNoCategorySeverity()} I tried to echo that property but I get an error how could I access to it?
this is the jelly template I am using (I took it from SO)
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define">
      <div class="content">  
          <html>
            <j:set var="cppcheckAction" value="${it.getAction('org.jenkinsci.plugins.cppcheck.CppcheckBuildAction')}" />
            <j:if test="${cppcheckAction!=null}">
            <j:set var="cppcheckResult" value="${cppcheckAction.getResult()}" />
            <j:if test="${cppcheckResult!=null}">
              <h2>Summary</h2>
                <style type="text/css">
            #cppcheckStatistics { width: auto; }
            #cppcheckStatistics .number { text-align: right; }
                </style>
                <table class="pane sortable" id="cppcheckStatistics">
                  <thead>
                    <tr>
                      <td class="pane-header">Severity</td>
                      <td class="pane-header">Count</td>
                      <td class="pane-header">Delta</td>
                    </tr>
                  </thead>
                  <tbody>
                    <tr>
                      <td class="pane">Error</td>
                      <td class="pane number">${cppcheckResult.statistics.getNumberErrorSeverity()}</td>
                      <td class="pane number">${cppcheckResult.getDiff().getNumberErrorSeverity()}</td>
                    </tr>
                    <tr>
                      <td class="pane">Warning</td>
                      <td class="pane number">${cppcheckResult.statistics.getNumberWarningSeverity()}</td>
                      <td class="pane number">${cppcheckResult.getDiff().getNumberWarningSeverity()}</td>
                    </tr>
                    <tr>
                      <td class="pane">Style</td>
                      <td class="pane number">${cppcheckResult.statistics.getNumberStyleSeverity()}</td>
                      <td class="pane number">${cppcheckResult.getDiff().getNumberStyleSeverity()}</td>
                    </tr>
                    <tr>
                      <td class="pane">Performance</td>
                      <td class="pane number">${cppcheckResult.statistics.getNumberPerformanceSeverity()}</td>
                      <td class="pane number">${cppcheckResult.getDiff().getNumberPerformanceSeverity()}</td>
                    </tr>
                    <tr>
                      <td class="pane">Portability</td>
                      <td class="pane number">${cppcheckResult.statistics.getNumberPortabilitySeverity()}</td>
                      <td class="pane number">${cppcheckResult.getDiff().getNumberPortabilitySeverity()}</td>
                    </tr>
                    <tr>
                      <td class="pane">Information</td>
                      <td class="pane number">${cppcheckResult.statistics.getNumberInformationSeverity()}</td>
                      <td class="pane number">${cppcheckResult.getDiff().getNumberInformationSeverity()}</td>
                    </tr>
                    <tr>
                      <td class="pane">No category</td>
                      <td class="pane number">${cppcheckResult.statistics.getNumberNoCategorySeverity()}</td>
                      <td class="pane number">${cppcheckResult.getDiff().getNumberNoCategorySeverity()}</td>
                    </tr>
                  </tbody>
                  <tfoot>
                    <tr class="sortbottom">
                      <td class="pane-header">Total</td>
                      <td class="pane-header number"><B><a href="${rooturl}${build.url}cppcheckResult">${cppcheckResult.report.getNumberTotal()}</a></B></td>
                      <td class="pane-header number"><B><a href="${rooturl}${build.url}cppcheckResult/source.all/?before=5&amp;after=5&amp;states=new">${cppcheckResult.getDiff().getNumberTotal()}</a></B></td>
                    </tr>
                  </tfoot>
                </table>
              </j:if>
            </j:if>
          </html>   
      </div>   
</j:jelly>

Ullrich Hafner

unread,
Apr 9, 2021, 8:40:34 AM4/9/21
to Jenkins Users
First of all: are you using the warnings-ng plugin or the cppcheck plugin in your build? They use different models. 

I’m not sure if there is an easy way to debug email ext templates in the meantime, I am not using it actively. 
But you can simply start with a subset of the script below and check which values produce a result and which not. 

jesus fernandez

unread,
Apr 9, 2021, 9:31:22 AM4/9/21
to Jenkins Users

I actually have tried both to publish the result, have not decided which one to use yet, any suggestion? I like the dashboard of the warnings-ng better, but I ilke from the publushcpp that you can see the line where the error is right from Jenkins without need to open the editor and look for the line...

Ullrich Hafner

unread,
Apr 9, 2021, 9:39:30 AM4/9/21
to Jenkins Users


I actually have tried both to publish the result,

But the object model of both is different, you need to choose the correct one in the email template!

have not decided which one to use yet, any suggestion?

I am biased as I am the author of the warnings plugin ;-)

I like the dashboard of the warnings-ng better, but I ilke from the publushcpp that you can see the line where the error is right from Jenkins without need to open the editor and look for the line...

jesus fernandez

unread,
Apr 9, 2021, 9:40:44 AM4/9/21
to Jenkins Users
hahaha oh gosh I should have known I watched your video on youtube a few days ago. 

jesus fernandez

unread,
Apr 9, 2021, 9:41:22 AM4/9/21
to Jenkins Users
but this is like god trying to explain something to a rock, I have just started in this world...hehehe

jesus fernandez

unread,
Apr 9, 2021, 10:05:31 AM4/9/21
to Jenkins Users
        But the object model of both is different, you need to choose the correct one in the email template!

Yes, that template I am using it with publishcpp at the moment but I am not able to get the value of any of their properties within my pipeline like if I try to echo to check its value I get an error 'groovy.lang.MissingPropertyException: No such property: cppcheckResult for class: groovy.lang.Binding' so I am stuck trying to get the total number of errors from each build

jesus fernandez

unread,
Apr 9, 2021, 10:57:56 AM4/9/21
to Jenkins Users
I have also tried this `def action = it.getAction('org.jenkinsci.plugins.cppcheck.CppcheckBuildAction')` which is how the variable get instantiated in the jelly template but I get ` java.lang.NullPointerException: Cannot invoke method getAction() on null object ` I am kind of lost here... any help is much appreciated
Reply all
Reply to author
Forward
0 new messages