Class RequestRunPrefill

java.lang.Object
io.jenkins.plugins.batchcontrol.ui.RequestRunPrefill

@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public final class RequestRunPrefill extends Object
D-60: carrying the values of a refused build submission into the job's Request Run form.

The contract (frozen for tests): the Request Run page <job>/batch-control/ accepts query parameters "p."<parameter name>; each one the job defines becomes the default shown for that parameter. Anything else is ignored. Pre-fill only changes what the form shows: nothing is queued or stored until the requester submits the form, whose field names are unchanged.

Only parameters whose value round-trips through a string are carried: those of a SimpleParameterDefinition (string, text, boolean, choice, run and the like), as the string form the definition's createValue(String) turns back into the same value (the text of a string, boolean or number value; the job#build id of a run value, T-06-103; any other value's own string form only when the definition rebuilds an equal value from it). A value without such a form is not carried. Sensitive values (password parameters, Secrets, anything ParameterValue.isSensitive()) are never written into the URL nor taken from it (P-03), file parameters cannot be, and a value the definition refuses (a choice outside its choices, a run that does not exist or the viewer cannot see) is dropped and leaves the job's default. Core's view of a run parameter does not show its default, so the form renders a carried run itself (selectedRunId(hudson.model.ParameterDefinition)). Values longer than 2000 characters are left out so the redirect stays within common URL limits, and a longer "p." query value is ignored; the user re-enters them. The whole encoded query is capped at 4000 characters: in definition order, a value that would take it past the cap is left out (S-33-03).

A crafted link can only pre-fill a form the viewer may already open: the viewer still reads and submits it, and every rendered value goes through the parameter definition's own view, which escapes it.

D-72: an incident rerun whose failed run has a value that cannot be recovered continues on the same form (rerunQuery(hudson.model.Job<?, ?>, java.util.Map<java.lang.String, java.lang.String>, java.lang.String)): the recoverable non-sensitive values travel as "p."<name> under the same caps, and "fromRerun"=<incident id> tells the form to say which values must be provided again. File parameters are never carried (isFileDefinition(hudson.model.ParameterDefinition)); carrying them from a refused build is issue #10.

  • Field Details

    • PREFIX

      public static final String PREFIX
      Query parameter prefix of a pre-filled value (frozen name).
      See Also:
    • FROM_RERUN

      public static final String FROM_RERUN
      D-72: query parameter naming the incident whose rerun continues on the Request Run form because a value of the failed run could not be recovered.
      See Also:
  • Method Details

    • carriedValues

      public static Map<String,String> carriedValues(Job<?,?> job, @CheckForNull List<ParameterValue> submitted)
      The values of submitted that may be carried to the Request Run form of job, by parameter name, in the job's definition order. Empty when nothing qualifies.
    • rerunQuery

      public static String rerunQuery(Job<?,?> job, Map<String,String> prefill, String incidentId)
      D-72: the query of the Request Run form an incident rerun continues on when a value of the failed run could not be recovered (RerunNeedsFormException): the prefill values the job defines as carriable parameters, under the same caps as carriedValues(hudson.model.Job<?, ?>, java.util.List<hudson.model.ParameterValue>) (2000 characters per value, 4000 for the encoded "p." part, definition order), then "fromRerun"=<incidentId>. A password parameter is never carried, whatever prefill holds.
    • isFileDefinition

      public static boolean isFileDefinition(@CheckForNull ParameterDefinition definition)
      Whether definition takes a file: core's FileParameterDefinition or a definition of the optional file-parameters plugin (stashedFile, base64File; through FileParametersSupport.isFileDefinition(hudson.model.ParameterDefinition)). A file is never carried into the form; the user selects it again.
    • toQuery

      public static String toQuery(Map<String,String> values)
      ?p.A=1&p.B=x for the given values, or the empty string for none.
    • apply

      public static List<ParameterDefinition> apply(List<ParameterDefinition> definitions, @CheckForNull org.kohsuke.stapler.StaplerRequest2 req)
      definitions with each carriable one that has a "p."<name> query parameter in req replaced by a copy defaulting to that value. Only GET requests are read: a POST is a submission, whose own values the form shows (e2e-03 DEF-09).
    • isPrefilled

      public static boolean isPrefilled(List<ParameterDefinition> definitions, @CheckForNull org.kohsuke.stapler.StaplerRequest2 req)
      Whether req is a GET carrying a "p."<name> value for at least one of definitions (the page then says where the values came from; constant text only).
    • rerunFromQuery

      @CheckForNull public static String rerunFromQuery(@CheckForNull jakarta.servlet.http.HttpServletRequest req)
      D-72a: the raw "fromRerun" value of req's query string alone (never its body), URL-decoded, or null. The Request Run form's action carries the validated incident reference there as well as in its hidden field, so that a submission refused before its body may be read (over the D-72 size cap) can still show the form linked to the incident. Unvalidated: the caller passes it to IncidentService#linkableIncident and ignores what that check refuses, exactly like the hidden field.
    • selectedRunId

      @CheckForNull public static String selectedRunId(@CheckForNull ParameterDefinition definition)
      T-06-103: the run the Request Run form must show selected for definition, or null when the definition's own view is right. Core's view of a run parameter lists the project's builds, newest first, without marking the definition's default; so a copy defaulting to a carried run (apply(java.util.List<hudson.model.ParameterDefinition>, org.kohsuke.stapler.StaplerRequest2), or a refused submission's value) would show the newest build instead. Non-null only for core's own RunParameterDefinition (a subclass may have its own view) whose default run is not the first one listed; the form then renders the same fields with that run selected.