[Plugin Development] How to change data associated to an action after the build is finished?

I’m developing a Jenkins plugin that executes performance measurements and thereby gives users the option to spot performance regressions that occurred for unit tests (GitHub - jenkinsci/peass-ci-plugin: Jenkins plugin for peass to support performance measurement in CI). After performance changes happened, the users look at the plugin, where all changes are summarized in one Action. Afterwards they review changes and potentially consider a change to be necessary due to required functional requrements, or they consider a change to require a refactoring etc…

To facilitate an overview over the reviewing results by the plugin users, I would like to save a state of the change reviewing. It’s no problem to create the form: peass-ci-plugin/index.jelly at b59e396cf7fecd73fc76e6db6a848b5fa8477404 · jenkinsci/peass-ci-plugin · GitHub, and at this part of the jelly code, it is clear which commit and test case has been reviewed.

How is it also possible to react to the requests? I had a look at the Jenkins code, and it seems like Descriptor and Describable are classes that could be used, but I did not find an example on their usage outside of regular Builder.

It would also be sufficient to me if I could get the pure request data, the serialization could happen as JSON in the current build folder, but I did not find anything about how to process that requests (besides the stapler basic documentation). Is it maybe possible to define a doUpdate( StaplerRequest request, StaplerResponse response ) method somewhere and thereby get the requests data?

EDIT
After some fiddeling, I made some progress on this issue.

In the Action, I added the following method to receive data via POST:

@RequirePOST
   public FormValidation doUpdate(@QueryParameter String myParameter,
         @QueryParameter String classification) {
      System.out.println("Parameter " + myParameter);
      System.out.println("Classification " + classification);

      return FormValidation.ok("Updated value");
   }

Now I need something to send the values on the page.

The form might look like this:

  <form action="update" method="post">
    <div style='display: none'>
     <f:entry name="myParameter" title="Choose Parameter" field="parameter">
        <f:textbox value="${myParameterValue}"/>
      </f:entry>
    </div>
    <f:entry name="classification" title="Choose Classificiation" field="classification">
      <select name="classification">
        <j:forEach var="option" items="${it.getChangeClassificationArray()}">
          <j:if test="${it.getClassification(project.getKey(), lastCommit, change.getTestcase()).equals(option)}">
            <option value="${option}" selected="selected">${option}</option>
          </j:if>
           <j:if test="${!it.getClassification(project.getKey(), lastCommit, change.getTestcase()).equals(option)}">
            <option value="${option}">${option}</option>
          </j:if>
        </j:forEach>
      </select>
    </f:entry>
    <f:validateButton method="update" type="submit" title="Classify" with="project,commit,testcase,classification" />
  </form>

The first three values need to be fixed and the classification should be configurable by the user to fixed values.

Unfortunately, using the f:validateButton results in a request to /jenkins/job/$JOBID/$BUILDID/overview/null/update (where overview is my action name), and the parameters look like myParameter=$PARAMETER&classification=TODO, so this variant contains two problems: there is null in the link and it does not contain a Jenkins crumb.

When I change the f:validateButton into an f:submit, the request goes to /jenkins/job/geomap-overview/40/overview/update and actually is handled by Java. Unfortunately, the payload is _.myParameter=$PARAMETER&classification=TODO&Jenkins-Crumb=df5d96f0a06ccd3e24682fee2972fc3074917134076b33f92bdc2cdaea4e3cf8&json=%7B%22myParameter%22%3A+%22$PARAMETER%22%2C+%22classification%22%3A+%22TODO%22%2C+%22Jenkins-Crumb%22%3A+%22df5d96f0a06ccd3e24682fee2972fc3074917134076b33f92bdc2cdaea4e3cf8%22%7D&Submit=%C3%9Cbernehmen. So, this has mainly the problem that the field with the name myParameter is mapped to _.myParameter, therefore it is not passed to the doUpdate method.

If anyone has an idea how to fix this button issue, I would be glad to hear it.

Fortunately, I found the solution:

It is still not nice that the f:submit causes loading of a new page and is not called by ajax, so I’ll accept an answer which additionally provides this.

EDIT

To not redirect to a new page everytime, it is possible to create an iframe (<iframe style="display: none" name="classificationResultFrame" id="classificationResultFrame"></iframe>) and to let the result be rendered to this frame (<form action="updateClassification" method="post" target='classificationResultFrame'>). The full example is in peass-ci-plugin/index.jelly at 753380006d1971b43704202ed85feb54ab834317 · jenkinsci/peass-ci-plugin · GitHub It would be nicer to do this via javascript and not always display the iframe, but I currently did not find a solution to do so.

as much as I wish otherwise, most plugin development conversations happen on the dev mailing list.

1 Like

Thanks for your feedback @DaGeRe .

1 Like

Thanks for the feedback, but now I’ve nearly solved it, so I’ll leave the issue here.