Jenkins view in build covering multiple plugin executions (Plugin development)

73 Views Asked by At

I am currently developing a Pipeline compatible Jenkins Plugin. The plugin executes tests in another program, saves the test results as artifacts and creates a report view in the build.

My problem is, if i execute the plugin multiple times (say in different pipeline stages) it will create a new report view for every execution. All those views contain the same content (the latest execution results) since there is only one set of variables saved by Jenkins for all the pages. Those variables get overwritten every time the plugin is executed.

My view is a basic Action as described in the extended Jenkins Plugin tutorial

public class xxxAction implements RunAction2

which gets called from my xxxBuilder.java

@Override
public void perform(Run<?, ?> run, FilePath workspace, Launcher launcher, TaskListener listener) throws InterruptedException, IOException {
...
run.addAction(new xxxAction())
...
}

How can i check/access my already existing view or load the variable values that Jenkins has saved from the last execution of my Plugin without creating a new view. My goal is to have one report view in the build, where i can display the data of all executions of my plugin in this build.

1

There are 1 best solutions below

0
Dragonchild On

After getting very lucky while sieving through code snippets on codota i managed to replace my view (and therefore recalculate the content) with each execution while keeping the data in it through a final custom object. I add and replace the action like this (there are replace functions as well):

if (run.getActions(PROVEtechAction.class).isEmpty()) {
    run.addAction(new PROVEtechAction());
} else {
    run.removeAction(run.getAction(PROVEtechAction.class));
    run.addAction(new PROVEtechAction());
}

My object to store my data looks like this:

public final class ResultObjects {

private static ArrayList<ResultObjects> TestResultList = new ArrayList<>();

public static ArrayList<ResultObjects> getTestResultList() {
    final ArrayList<ResultObjects> res = new ArrayList<>(TestResultList);
    return res;
}

public String someData;

...

public ResultObjects() {
    TestResultList.add(this);
    this.someData = null;
    ...
}
}

Which is basically just a static list to which i add my results.