Search in sources :

Example 1 with InputAction

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());
    }
}
Also used : InputAction(org.jenkinsci.plugins.workflow.support.steps.input.InputAction) HttpResponse(org.kohsuke.stapler.HttpResponse) IOException(java.io.IOException) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) InputStepExecution(org.jenkinsci.plugins.workflow.support.steps.input.InputStepExecution) JSONObject(net.sf.json.JSONObject) ServiceException(io.jenkins.blueocean.commons.ServiceException) JSONObject(net.sf.json.JSONObject) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

ServiceException (io.jenkins.blueocean.commons.ServiceException)1 IOException (java.io.IOException)1 TimeoutException (java.util.concurrent.TimeoutException)1 JSONObject (net.sf.json.JSONObject)1 WorkflowRun (org.jenkinsci.plugins.workflow.job.WorkflowRun)1 InputAction (org.jenkinsci.plugins.workflow.support.steps.input.InputAction)1 InputStepExecution (org.jenkinsci.plugins.workflow.support.steps.input.InputStepExecution)1 HttpResponse (org.kohsuke.stapler.HttpResponse)1