Plugins - How to replace default widgets

Hi,

Might be a bit of a newbie question (first time i’v attempting writing a plugin).

I’ve been working on a plugin which is intended to replace the build executors widget to allow us to do some filtering there. I’m now struggling to find how I am meant to be removing the default widget however. The comments on the code in for the ExecutorsWidget suggets using the getWidgets() function to swap in my own (jenkins/core/src/main/java/jenkins/widgets/ExecutorsWidget.java at 5df30de4358ca93db17eb1d80a6b3a6f1c92ffad · jenkinsci/jenkins · GitHub), but calling this on the instance doesn’t seem to show the existing widget, and the list itself seems to be unmodifiable.

I’m currently testing the plugin using mvn hpi:run and it seems to be using jenkins 2.440.3 in this configuration
Any advice where I should be going with this?

Many thanks

There is already a plugin that allows to filter executors. GitHub - jenkinsci/build-executors-filter-offline-plugin: This is a plugin that can filter out the offline nodes in the build executors status widget.
You could try out if the approach there still works, if yes it might also be an option to extend that plugin instead of writing a new one.

btw since Jenkins 2.463 the executors widget will only show active executors and no longer the idle ones.

Hey Markus
Thanks for your reply - The approach there unfortunately has the same issue i’m running into too (both the plugin widget and default widget being shown), using the same method I was trying.

ah right the way widgets are chosen has changed. There is now a WidgetFactory and there are 3 extensions to show the executors widget on views, computers and computerset.
You would need to remove those factories from the extensionlist

WidgetFactory wf : ExtensionList.lookup(WidgetFactory.class)
wf.removeIf(i -> i instanceof ComputerFactoryImpl || i instanceof ComputerFactoryImpl || i instanceof ViewFactoryImpl || i instanceof ComputerSetFactoryImpl)

The 3 classes are from ExecutorsWidget
Don’t know if that really works though

1 Like

Ah thank you, removing it like that did the trick!