Search in sources :

Example 1 with Failure

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);
    }
}
Also used : ModifiableTopLevelItemGroup(jenkins.model.ModifiableTopLevelItemGroup) Error(io.jenkins.blueocean.commons.ErrorMessage.Error) Failure(hudson.model.Failure)

Example 2 with Failure

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;
}
Also used : FormException(hudson.model.Descriptor.FormException) BuildStepDescriptor(hudson.tasks.BuildStepDescriptor) Descriptor(hudson.model.Descriptor) BulkChange(hudson.BulkChange) Failure(hudson.model.Failure)

Example 3 with Failure

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);
    }
}
Also used : ServletException(javax.servlet.ServletException) FileItem(org.apache.commons.fileupload.FileItem) HttpRedirect(org.kohsuke.stapler.HttpRedirect) ServletFileUpload(org.apache.commons.fileupload.servlet.ServletFileUpload) IOException(java.io.IOException) DiskFileItemFactory(org.apache.commons.fileupload.disk.DiskFileItemFactory) File(java.io.File) Failure(hudson.model.Failure) ServletException(javax.servlet.ServletException) CycleDetectedException(hudson.util.CyclicGraphDetector.CycleDetectedException) IOException(java.io.IOException)

Example 4 with Failure

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/");
}
Also used : UpdateSite(hudson.model.UpdateSite) Failure(hudson.model.Failure)

Example 5 with Failure

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());
    }
}
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) Failure(hudson.model.Failure) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

Failure (hudson.model.Failure)5 IOException (java.io.IOException)2 BulkChange (hudson.BulkChange)1 Descriptor (hudson.model.Descriptor)1 FormException (hudson.model.Descriptor.FormException)1 UpdateSite (hudson.model.UpdateSite)1 BuildStepDescriptor (hudson.tasks.BuildStepDescriptor)1 CycleDetectedException (hudson.util.CyclicGraphDetector.CycleDetectedException)1 Error (io.jenkins.blueocean.commons.ErrorMessage.Error)1 ServiceException (io.jenkins.blueocean.commons.ServiceException)1 File (java.io.File)1 TimeoutException (java.util.concurrent.TimeoutException)1 ServletException (javax.servlet.ServletException)1 ModifiableTopLevelItemGroup (jenkins.model.ModifiableTopLevelItemGroup)1 JSONObject (net.sf.json.JSONObject)1 FileItem (org.apache.commons.fileupload.FileItem)1 DiskFileItemFactory (org.apache.commons.fileupload.disk.DiskFileItemFactory)1 ServletFileUpload (org.apache.commons.fileupload.servlet.ServletFileUpload)1 WorkflowRun (org.jenkinsci.plugins.workflow.job.WorkflowRun)1 InputAction (org.jenkinsci.plugins.workflow.support.steps.input.InputAction)1