use of hudson.model.Failure in project blueocean-plugin by jenkinsci.
the class AbstractMultiBranchCreateRequest method validateInternal.
private void validateInternal(String name, BlueScmConfig scmConfig, BlueOrganization organization) {
checkUserIsAuthenticatedAndHasItemCreatePermission(organization);
// If scmConfig is empty then we are missing the uri and name
if (scmConfig == null) {
throw fail(new Error("scmConfig", ErrorCodes.MISSING.toString(), "scmConfig is required"));
}
if (scmConfig.getUri() == null) {
throw fail(new Error(ERROR_FIELD_SCM_CONFIG_URI, ErrorCodes.MISSING.toString(), ERROR_FIELD_SCM_CONFIG_URI + " is required"));
}
if (getName() == null) {
throw fail(new Error(ERROR_FIELD_SCM_CONFIG_NAME, ErrorCodes.MISSING.toString(), ERROR_FIELD_SCM_CONFIG_NAME + " is required"));
}
List<Error> errors = Lists.newLinkedList(validate(name, scmConfig));
// Validate that name matches rules
try {
Jenkins.getInstance().getProjectNamingStrategy().checkName(getName());
} catch (Failure f) {
errors.add(new Error(ERROR_FIELD_SCM_CONFIG_NAME, Error.ErrorCodes.INVALID.toString(), getName() + " in not a valid name"));
}
ModifiableTopLevelItemGroup parent = getParent(organization);
if (parent.getItem(name) != null) {
errors.add(new Error(ERROR_NAME, Error.ErrorCodes.ALREADY_EXISTS.toString(), getName() + " already exists"));
}
if (!errors.isEmpty()) {
throw fail(errors);
}
}
use of hudson.model.Failure in project promoted-builds-plugin by jenkinsci.
the class PromotionProcess method fromJson.
/**
* Creates unconnected {@link PromotionProcess} instance from the JSON configuration.
* This is mostly only useful for capturing its configuration in XML format.
* @param req Request
* @param o JSON object with source data
* @throws FormException form submission issue, includes form validation
* @throws IOException {@link PromotionProcess} creation issue
* @return Parsed promotion process
*/
public static PromotionProcess fromJson(StaplerRequest req, JSONObject o) throws FormException, IOException {
String name = o.getString("name");
try {
Jenkins.checkGoodName(name);
} catch (Failure f) {
throw new Descriptor.FormException(f.getMessage(), name);
}
PromotionProcess p = new PromotionProcess(null, name);
BulkChange bc = new BulkChange(p);
try {
// apply configuration. prevent it from trying to save to disk while we do this
p.configure(req, o);
} finally {
bc.abort();
}
return p;
}
use of hudson.model.Failure in project hudson-2.x by hudson.
the class PluginManager method doUploadPlugin.
/**
* Uploads a plugin.
*/
public HttpResponse doUploadPlugin(StaplerRequest req) throws IOException, ServletException {
try {
Hudson.getInstance().checkPermission(Hudson.ADMINISTER);
ServletFileUpload upload = new ServletFileUpload(new DiskFileItemFactory());
// Parse the request
FileItem fileItem = (FileItem) upload.parseRequest(req).get(0);
String fileName = Util.getFileName(fileItem.getName());
if ("".equals(fileName))
return new HttpRedirect("advanced");
if (!fileName.endsWith(".hpi"))
throw new Failure(hudson.model.Messages.Hudson_NotAPlugin(fileName));
fileItem.write(new File(rootDir, fileName));
fileItem.delete();
pluginUploaded = true;
return new HttpRedirect(".");
} catch (IOException e) {
throw e;
} catch (Exception e) {
// grrr. fileItem.write throws this
throw new ServletException(e);
}
}
use of hudson.model.Failure in project hudson-2.x by hudson.
the class PluginManager method doInstall.
/**
* Performs the installation of the plugins.
*/
public void doInstall(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException {
Enumeration<String> en = req.getParameterNames();
while (en.hasMoreElements()) {
String n = en.nextElement();
if (n.startsWith("plugin.")) {
n = n.substring(7);
if (n.indexOf(".") > 0) {
String[] pluginInfo = n.split("\\.");
UpdateSite.Plugin p = Hudson.getInstance().getUpdateCenter().getById(pluginInfo[1]).getPlugin(pluginInfo[0]);
if (p == null)
throw new Failure("No such plugin: " + n);
p.deploy();
}
}
}
rsp.sendRedirect("../updateCenter/");
}
use of hudson.model.Failure 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.BadRequestException("id is required");
}
if (body.get(PARAMETERS_ELEMENT) == null && body.get(ABORT_ELEMENT) == null) {
throw new ServiceException.BadRequestException("parameters is required");
}
WorkflowRun run = node.getRun();
InputAction inputAction = run.getAction(InputAction.class);
if (inputAction == null) {
throw new ServiceException.BadRequestException("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.BadRequestException(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();
}
try {
execution.preSubmissionCheck();
} catch (Failure f) {
throw new ServiceException.BadRequestException(f.getMessage());
}
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