use of org.jenkinsci.plugins.pipeline.modeldefinition.actions.RestartDeclarativePipelineAction in project blueocean-plugin by jenkinsci.
the class PipelineNodeImpl method restart.
public HttpResponse restart(StaplerRequest request) {
try {
JSONObject body = JSONObject.fromObject(IOUtils.toString(request.getReader()));
boolean restart = body.getBoolean("restart");
if (restart && isRestartable()) {
LOGGER.debug("submitInputStep, restart: {}, step: {}", restart, this.getDisplayName());
RestartDeclarativePipelineAction restartDeclarativePipelineAction = this.run.getAction(RestartDeclarativePipelineAction.class);
Queue.Item item = restartDeclarativePipelineAction.run(this.getDisplayName());
BluePipeline bluePipeline = BluePipelineFactory.getPipelineInstance(this.run.getParent(), this.parent);
BlueQueueItem queueItem = QueueUtil.getQueuedItem(bluePipeline.getOrganization(), item, run.getParent());
if (queueItem != null) {
// If the item is still queued
return (req, rsp, node1) -> {
rsp.setStatus(HttpServletResponse.SC_OK);
rsp.getOutputStream().print(Export.toJson(queueItem.toRun()));
};
}
final WorkflowRun restartRun = getRun(run.getParent(), item.getId());
if (restartRun != null) {
return (req, rsp, node1) -> {
rsp.setStatus(HttpServletResponse.SC_OK);
rsp.getOutputStream().print(Export.toJson(new PipelineRunImpl(restartRun, parent, bluePipeline.getOrganization())));
};
} else {
// For some reason could not be added to the queue
throw new ServiceException.UnexpectedErrorException("Run was not added to queue.");
}
}
// ISE cant happen if stage not restartable or anything else :)
} catch (Exception e) {
LOGGER.warn("error restarting stage: " + e.getMessage(), e);
throw new ServiceException.UnexpectedErrorException(e.getMessage());
}
return null;
}
Aggregations