0
votes

I'm developing my own custom Jenkins plugin that generates a report from GT Metrix. The lack of documentation is making this extremely difficult.

What I have so far:

I've successfully built a plugin that compiles. You set a username and api key in the global Jenkins setting. You set a website in your build config. When you build the project it will run a GT Metrix report and wait for it to finish, then download all of the information from the report. I've set up a project action with a floatingBox.jelly and the HTML shows up on the project page.

What I need:

Now that I have the report and I have the floatingBox.jelly showing up on the project page I want it to display values from the reports so I do ${from.report.pageLoadTime}. I believe I've set up everything correctly. If I do ${from.report} it displays the reference like org.jenkinsci.plugins.gtmetrix.GtMetrixReportResource@1bd5b1dc. but the extra .pageLoadTime displays nothing. I don't get why it has the resource but it won't call any functions from inside that resource.

Source Code https://github.com/chrislondon/jenkins-gtmetrix-plugin

1

1 Answers

1
votes

Your jelly code needs to look like this

<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:i="jelly:fmt" xmlns:local="local">
    <j:set var="lastResult" value="${from.lastResult}"/>

    <div class="content">
        <h2>GT Metrix Summary</h2>

        <j:if test="${lastResult != null}">
            <h3>Page Load Time: ${lastResult.getPageLoadTime()}</h3>

        </j:if>

        <j:if test="${lastResult == null}">
            Unable to find report. ${report}
        </j:if>

    </div>
</j:jelly>

and I added a method to your class GtMetrixBuildAction

public String getPageLoadTime(){
    return getReport().getPageLoadTime();
}

What I think your main problem is is that your final class where your report data is is not Describable so the jelly code can't find it. All your other classes are Describable


EDIT How to make a class Describable

You can make your class describable by inheriting from AbstractDescribableImpl

public abstract class YourClass extends AbstractDescribableImpl<YourClass> 
    implements Comparable, Describable<YourClass> ...

I don't think you need the Comparable but I can't check at the moment. You will then have to fix up the concrete classes

Here is one I prepared earlier

You might also need some jelly files to display it, probably using property