Class IncidentService
java.lang.Object
io.jenkins.plugins.batchcontrol.ops.IncidentService
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class)
public final class IncidentService
extends Object
The single entry point for every
Incident lifecycle operation (SPEC item 11, D-10,
D-19): automatic registration from completed builds, forward-only handling transitions
(OPEN -> ACKNOWLEDGED -> RESOLVED), comments, rerun requests and the automatic
resolvedByRunId link. No other class may change an incident's status.
Every load→validate→mutate→persist sequence runs under one ReentrantLock, so
concurrent transitions serialize and the loser is refused on the already-changed status.
Failure families follow RunRequestService: IllegalArgumentException for
bad input (unknown id, blank comment where required), IllegalStateException for
refused transitions.
-
Method Summary
Modifier and TypeMethodDescriptionacknowledge(String id, String comment) OPEN -> ACKNOWLEDGED; any other current status is refused (forward-only).addComment(String id, String comment) Appends a comment to the incident history without changing the status — allowed in every status, RESOLVED included (SPEC section 4).booleanWhether the current user could request a rerun ofincident(e2e-03 DEF-12): the incident's job still exists andRunRequestService.canRequest(hudson.model.Job<?, ?>)holds for it, which is whatrerun(java.lang.String, java.lang.String)and the request creation check.static IncidentServiceget()linkableIncident(String incidentId, Job<?, ?> job) D-72a (SPEC item 11): the incident a run request submitted from the Request Run form may be linked to, when an incident rerun fell back to that form and the form carried the incident id back.voidlinkResolvedBy(String incidentId, String runId) Records the successful linked rerun on the incident (SPEC item 11): setsresolvedByRunIdbut never touches the status — resolution stays a human decision.Every incident created in the given month, in creation order.Loads an incident by id, ornull.maskedParameters(Run<?, ?> run) The build's parameters in their masked display form (ParameterDisplay, D-72): a sensitive value is the mask, a file value[file] <original file name>.openForRun(Run<?, ?> run) Opens an incident for a completed build whose result is in the configuredincidentResults— regardless of what caused the build (SPEC item 11, D-10).voidrecordRerunRequest(String incidentId, String requestId) Lists the stored run requestrequestIdamong the incident's rerun requests (the link back from the incident; the request itself carriesincidentId).requireRerunTarget(String incidentId, Job<?, ?> job) The incident a run request forjobis linked to (SPEC item 11): it must exist and belong tojob.Creates a rerunRunRequestcarrying the failed run's own parameter values (D-72: taken from the build'sParametersAction, original secrets and recoverable file values included) and links it both ways:request.incidentIdandincident.rerunRequestIds.Approver-set form (D-37) ofrerun(String, String).ACKNOWLEDGED -> RESOLVEDonly (SPEC section 4: OPEN must pass ACKNOWLEDGED first).
-
Method Details
-
get
-
load
Loads an incident by id, ornull. -
list
Every incident created in the given month, in creation order. -
openForRun
Opens an incident for a completed build whose result is in the configuredincidentResults— regardless of what caused the build (SPEC item 11, D-10). Called by the run listener; returnsnullwhen the result is outside the configured set.D-19: the stored logTail masks the build's sensitive parameter values and encrypted
Secretpayloads; other secrets echoed to the console are a documented detection limit. The stored parameters mask sensitive values entirely. -
acknowledge
OPEN -> ACKNOWLEDGED; any other current status is refused (forward-only). R1-01: a comment holding a character XML 1.0 cannot store is refused (IllegalArgumentException) before anything changes. -
resolve
ACKNOWLEDGED -> RESOLVEDonly (SPEC section 4: OPEN must pass ACKNOWLEDGED first). R1-01: the comment is checked as foracknowledge(java.lang.String, java.lang.String). -
addComment
Appends a comment to the incident history without changing the status — allowed in every status, RESOLVED included (SPEC section 4). The entry is recorded against the incident's current status. R1-01: the comment is checked as foracknowledge(java.lang.String, java.lang.String). -
rerun
Creates a rerunRunRequestcarrying the failed run's own parameter values (D-72: taken from the build'sParametersAction, original secrets and recoverable file values included) and links it both ways:request.incidentIdandincident.rerunRequestIds. The caller becomes the requester; permission and approver checks are those ofRunRequestService.create(hudson.model.Job<?, ?>, java.util.List<hudson.model.ParameterValue>, java.lang.String, java.lang.String).- Throws:
RerunNeedsFormException- when a value of the failed run cannot be recovered (a stashed file, a core file whose copy under the build is gone, a deleted build); no request is created and the rerun continues on the job's Request Run form
-
canRerun
Whether the current user could request a rerun ofincident(e2e-03 DEF-12): the incident's job still exists andRunRequestService.canRequest(hudson.model.Job<?, ?>)holds for it, which is whatrerun(java.lang.String, java.lang.String)and the request creation check. Screens show the rerun form only then. -
rerun
Approver-set form (D-37) ofrerun(String, String). -
linkableIncident
@CheckForNull public String linkableIncident(@CheckForNull String incidentId, @CheckForNull Job<?, ?> job) D-72a (SPEC item 11): the incident a run request submitted from the Request Run form may be linked to, when an incident rerun fell back to that form and the form carried the incident id back. Returns the stored incident's id only when all of these hold, elsenull:incidentIdhas the shape of a store identifier (PathCodec.isId(java.lang.String)) and the incident exists;- it belongs to
job(by full name); - the current user holds
BatchControl/ViewHistory(the Incidents screen, where the rerun button is) and may request a run ofjob(BatchControl/RequestandItem/Read,RunRequestService.canRequest(hudson.model.Job<?, ?>)), the rights of a rerun.
RunRequestService.create(Job, List, String, List, String), which links the request to the incident so a successful run recordsresolvedByRunId. Read only. -
requireRerunTarget
The incident a run request forjobis linked to (SPEC item 11): it must exist and belong tojob. Called by request creation before anything is stored.- Throws:
IllegalArgumentException- when there is no such incident of that job
-
recordRerunRequest
Lists the stored run requestrequestIdamong the incident's rerun requests (the link back from the incident; the request itself carriesincidentId). Called by request creation once the request is stored, outside the request service's lock; adding the same id again changes nothing. Never throws: the request is already stored and itsincidentIdalone drivesresolvedByRunId, so a failure is only logged. -
linkResolvedBy
Records the successful linked rerun on the incident (SPEC item 11): setsresolvedByRunIdbut never touches the status — resolution stays a human decision. Called by the run listener when a request-linked build ends SUCCESS. -
maskedParameters
The build's parameters in their masked display form (ParameterDisplay, D-72): a sensitive value is the mask, a file value[file] <original file name>. The plaintext of a sensitive value never leaves this method.
-