use of org.jenkinsci.plugins.workflow.support.steps.input.InputAction in project blueocean-plugin by jenkinsci.
the class PipelineStepImpl method submitInputStep.
@Override
public HttpResponse submitInputStep(StaplerRequest request) {
JSONObject body;
try {
body = JSONObject.fromObject(IOUtils.toString(request.getReader()));
} catch (IOException e) {
throw new ServiceException.UnexpectedErrorException(e.getMessage());
}
String id = body.getString(ID_ELEMENT);
if (id == null) {
throw new ServiceException.BadRequestExpception("id is required");
}
if (body.get(PARAMETERS_ELEMENT) == null && body.get(ABORT_ELEMENT) == null) {
throw new ServiceException.BadRequestExpception("parameters is required");
}
WorkflowRun run = node.getRun();
InputAction inputAction = run.getAction(InputAction.class);
if (inputAction == null) {
throw new ServiceException.BadRequestExpception("Error processing Input Submit request. This Run instance does not" + " have an InputAction.");
}
try {
InputStepExecution execution = inputAction.getExecution(id);
if (execution == null) {
throw new ServiceException.BadRequestExpception(String.format("Error processing Input Submit request. This Run instance does not" + " have an Input with an id of '%s'.", id));
}
//if abort, abort and return
if (body.get(ABORT_ELEMENT) != null && body.getBoolean(ABORT_ELEMENT)) {
return execution.doAbort();
}
//XXX: execution.doProceed(request) expects submitted form, otherwise we could have simply used it
preSubmissionCheck(execution);
Object o = parseValue(execution, JSONArray.fromObject(body.get(PARAMETERS_ELEMENT)), request);
HttpResponse response = execution.proceed(o);
for (PipelineInputStepListener listener : ExtensionList.lookup(PipelineInputStepListener.class)) {
listener.onStepContinue(execution.getInput(), run);
}
return response;
} catch (IOException | InterruptedException | TimeoutException e) {
throw new ServiceException.UnexpectedErrorException("Error processing Input Submit request." + e.getMessage());
}
}
Aggregations