Plugin project action NullPointerException after Jenkins restart

57 views
Skip to first unread message

Matej Artač

unread,
Jun 20, 2017, 10:45:23 AM6/20/17
to Jenkins Developers
Greetings,

I have a plug-in [1] that worked for freestyle projects. I converted it to support Jenkins Pipelines. It generally works as it should, except after Jenkins starts and before a new build gets executed. In this case, when I open the dashboard of the project configured with the plug-in, I get an error:

    WARNING: Caught exception evaluating: it.getMetricNames() in /jenkins/job/QualityTestingPipeline/dice-dashboard/. Reason: java.lang.NullPointerException
    java.lang.NullPointerException
        at org.jenkinsci.plugins.workflow.job.WorkflowJob._getRuns(WorkflowJob.java:231)
        at org.jenkinsci.plugins.workflow.job.WorkflowJob._getRuns(WorkflowJob.java:113)
        at hudson.model.Job.getBuilds(Job.java:706)
        at eu.diceh2020.jenkinsci.plugins.diceqt.DiceQTResultProjectAction.getCurrentBuildHistory(DiceQTResultProjectAction.java:160)
        at eu.diceh2020.jenkinsci.plugins.diceqt.DiceQTResultProjectAction.getMetricNames(DiceQTResultProjectAction.java:105)

I have seen this post [2] that looked like it was addressing a similar problem. I tried to apply it for my plug-in [3], but now I get a NullPointerException even earlier:

    Caused by: java.lang.NullPointerException
        at eu.diceh2020.jenkinsci.plugins.diceqt.DiceQTResultProjectAction.getCurrentBuildHistory(DiceQTResultProjectAction.java:171)
        at eu.diceh2020.jenkinsci.plugins.diceqt.DiceQTResultProjectAction.doDisplayGraph(DiceQTResultProjectAction.java:190)

So now the project doesn't get initialized at all. Also, none of the RunAction2 methods seem to be called, at least there is no output in the console for them. What am I missing?

Thank you!
Matej


Jesse Glick

unread,
Jun 20, 2017, 12:31:20 PM6/20/17
to Jenkins Dev
You seem to have one `Action` holding on to others, which does not
make sense. Either attach all the `Actions` at top level
(`Run.addAction`), or make the nested structures extend `Object` and
implement `RunAction2` on the actual single `Action`.

Matej Artač

unread,
Jun 21, 2017, 8:34:56 AM6/21/17
to Jenkins Developers
Hello Jesse,

I'm afraid I don't completely understand what is wrong and how I should approach the issue.

You seem to have one `Action` holding on to others, which does not make sense.

I have the exact same situation as in this post [1]: I have one Action, the DiceQTResultBuildAction, that takes care of the display and an icon for a build, and it is also the one that the Recorder adds to the build to be preserved with the build. But then I also have DiceQTResultProjectAction, which shows a chart over past builds on the project dashboard, and which I also need to add a route to a special display and to add its own link and icon. This works nicely in the Freestyle project, but again according to this post [1], the build action needs to make the project action discoverable to Jenkins, otherwise the project dasboard doesn't work.

Either attach all the `Actions` at top level (`Run.addAction`), or make the nested structures extend `Object` and implement `RunAction2` on the actual single `Action`.

By the actual single Action you mean the Build action? What is considered here as a top level? Won't extending Object remove the ability to show icons on the appropriate level?

Thank you and best regards,
Matej



Dne torek, 20. junij 2017 18.31.20 UTC+2 je oseba Jesse Glick napisala:

Jesse Glick

unread,
Jun 21, 2017, 11:03:37 AM6/21/17
to Jenkins Dev
On Wed, Jun 21, 2017 at 3:20 AM, Matej Artač <matej.a...@gmail.com> wrote:
>> Either attach all the `Actions` at top level (`Run.addAction`), or make
>> the nested structures extend `Object` and implement `RunAction2` on the
>> actual single `Action`.
>
> By the actual single Action you mean the Build action? What is considered
> here as a top level? Won't extending Object remove the ability to show icons
> on the appropriate level?

Yes, so if you are using all the actions as actual `Action`s then you
need to attach them all to the build, using `Run.addAction` on each.
And then get rid of the field in one action holding a list of other
actions.

It is hard to discuss details of mistakes in your code over a mailing
list. Much better to propose changes via pull request and then request
reviewers, where individual lines can be annotated.

Matej Artač

unread,
Jun 22, 2017, 2:01:32 PM6/22/17
to Jenkins Developers
Hello Jesse,

thank you again for your tips. I have made an update of the code [1] according to my understanding of your comments. Note that I implemented `RunAction2` methods on both Action classes just to see what happens. However, these changes alone do not resolve my problem: the project action does not get invoked by Jenkins - I do not see any visualizations implemented in the plug-in, and I get `No matching rule was found on <org.jenkinsci.plugins.workflow.job.WorkflowJob@7be09d78[DiceTestPipeline]> for "/dice-dashboard"`.

I have created a pull request [2] where hopefully it will be easier to comment the changes and the code.

Thank you and best regards,
Matej

Matej Artač

unread,
Jun 23, 2017, 9:22:27 AM6/23/17
to Jenkins Developers
Thanks again for all the hints. I was of course going in the wrong direction for my use case, so pulling out helps. And reading this page [1].

So I resolved my problem by first removing the weird collections of Job actions within Run actions. Then I added an extension that implements TransientActionFactory. This now creates a collection of a single element, which is my project action. And considering that the action is transient, i.e., uses persistance of build actions but does not persist anything by itself. Sure enough, the chart now appears on the dashboard and the route to the special view gets matched properly.

At first, however, this oversolved the problem, because now that chart would appear on all the projects' dashboards. So I added a check for any sensible content before registering the action.

These [2] are now my changes that work.

Best regards,
Matej


Dne četrtek, 22. junij 2017 20.01.32 UTC+2 je oseba Matej Artač napisala:
Reply all
Reply to author
Forward
0 new messages