Avoid duplications of sidebar links when running the same plugin twice within a job

We developed a post plugin years ago that as part of what it’s doing, it also place some sidebar links at the build and job level. GitHub - jenkinsci/vmanager-plugin: A plugin to allow Jenkins Steps with Cadence vManager API

The issue we have is when running this plugin inside pipeline more than once, those links are getting placed for each usage of the plugin within that job, ending up with several duplicated links for the same exact URL’s.

Is there anyway to avoid it either by writing the plugin differently, or running it differently?



There will be a sidebar link for each action added to the run. For example: vmanager-plugin/DSLPublisher.java at b72ab3b9dc23de0d848436e57dfd20874992ef80 · jenkinsci/vmanager-plugin · GitHub

You could rewrite the actions to contain a list of the relevant data. Then update publishing to check for existing actions and merge the new data instead of adding a new action.

Thank you, so that seems to solve the issue:
DSLBuildAction buildAction = new DSLBuildAction(“NA”, run);
List buildActionList = run.getActions(DSLBuildAction.class);
if (buildActionList.isEmpty()){

This code is already implemented (in a thread-safe manner) in run.addOrReplaceAction(new DslAction()).

Actually now that you mention thread-safe, it does make sense, but I might get into a smaller corner-case in which the previous identical action is still working and I don’t want it to be replaced.

Is there a way to check if the previous identical action is still running?

An action should be a dumb view model object without any running code (it should just serve as UI model only). So if the action is deleted then it will exist - as any other Java object - until it is not needed anymore (Garbage collector).