Search in sources :

Example 6 with AbortException

use of hudson.AbortException in project workflow-job-plugin by jenkinsci.

the class WorkflowRun method finish.

/**
 * Handles normal build completion (including errors) but also handles the case that the flow did not even start correctly, for example due to an error in {@link FlowExecution#start}.
 */
private void finish(@Nonnull Result r, @CheckForNull Throwable t) {
    setResult(r);
    duration = Math.max(0, System.currentTimeMillis() - getStartTimeInMillis());
    LOGGER.log(Level.INFO, "{0} completed: {1}", new Object[] { toString(), getResult() });
    if (listener == null) {
        LOGGER.log(Level.WARNING, this + " failed to start", t);
    } else {
        RunListener.fireCompleted(WorkflowRun.this, listener);
        if (t instanceof AbortException) {
            listener.error(t.getMessage());
        } else if (t instanceof FlowInterruptedException) {
            ((FlowInterruptedException) t).handle(this, listener);
        } else if (t != null) {
            // TODO 2.43+ use Functions.printStackTrace
            listener.getLogger().println(Functions.printThrowable(t).trim());
        }
        listener.finished(getResult());
        listener.closeQuietly();
    }
    logsToCopy = null;
    try {
        save();
    } catch (Exception x) {
        LOGGER.log(Level.WARNING, "failed to save " + this, x);
    }
    Timer.get().submit(() -> {
        try {
            getParent().logRotate();
        } catch (Exception x) {
            LOGGER.log(Level.WARNING, "failed to perform log rotation after " + this, x);
        }
    });
    onEndBuilding();
    if (completed != null) {
        synchronized (completed) {
            completed.set(true);
        }
    }
    FlowExecutionList.get().unregister(new Owner(this));
    try {
        StashManager.maybeClearAll(this);
    } catch (IOException x) {
        LOGGER.log(Level.WARNING, "failed to clean up stashes from " + this, x);
    }
    FlowExecution exec = getExecution();
    if (exec != null) {
        FlowExecutionListener.fireCompleted(exec);
    }
}
Also used : FlowExecutionOwner(org.jenkinsci.plugins.workflow.flow.FlowExecutionOwner) FlowExecution(org.jenkinsci.plugins.workflow.flow.FlowExecution) FlowInterruptedException(org.jenkinsci.plugins.workflow.steps.FlowInterruptedException) IOException(java.io.IOException) AbortException(hudson.AbortException) IOException(java.io.IOException) FlowInterruptedException(org.jenkinsci.plugins.workflow.steps.FlowInterruptedException) AbortException(hudson.AbortException)

Example 7 with AbortException

use of hudson.AbortException in project gitea-plugin by jenkinsci.

the class GiteaSCMSource method gitea.

/*package*/
Gitea gitea() throws AbortException {
    GiteaServer server = GiteaServers.get().findServer(serverUrl);
    if (server == null) {
        throw new AbortException("Unknown server: " + serverUrl);
    }
    StandardCredentials credentials = credentials();
    SCMSourceOwner owner = getOwner();
    if (owner != null) {
        CredentialsProvider.track(owner, credentials);
    }
    return Gitea.server(serverUrl).as(AuthenticationTokens.convert(GiteaAuth.class, credentials));
}
Also used : SCMSourceOwner(jenkins.scm.api.SCMSourceOwner) GiteaServer(org.jenkinsci.plugin.gitea.servers.GiteaServer) StandardCredentials(com.cloudbees.plugins.credentials.common.StandardCredentials) GiteaAuth(org.jenkinsci.plugin.gitea.client.api.GiteaAuth) AbortException(hudson.AbortException)

Example 8 with AbortException

use of hudson.AbortException in project promoted-builds-plugin by jenkinsci.

the class Status method doBuild.

/**
 * Schedules a new build.
 * @param req Request
 * @param rsp Response
 * @throws IOException Functional error
 * @throws ServletException Request handling error
 */
@POST
public void doBuild(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException {
    final PromotionProcess process = getProcess();
    if (process == null) {
        throw new AbortException("Cannot retrieve the promotion process");
    }
    AbstractBuild<?, ?> target = getTarget();
    if (target == null) {
        throw new AbortException("Cannot get the target build to be promoted");
    }
    ManualCondition manualCondition = (ManualCondition) process.getPromotionCondition(ManualCondition.class.getName());
    // TODO: Use PromotionPermissionHelper.checkPermission instead, but consider issues with backwards compatibility.
    if (!PromotionPermissionHelper.hasPermission(target.getProject(), manualCondition)) {
        return;
    }
    JSONObject formData = req.getSubmittedForm();
    List<ParameterValue> paramValues = null;
    if (formData != null) {
        paramValues = new ArrayList<ParameterValue>();
        if (manualCondition != null) {
            List<ParameterDefinition> parameterDefinitions = manualCondition.getParameterDefinitions();
            if (parameterDefinitions != null && !parameterDefinitions.isEmpty()) {
                JSONArray a = JSONArray.fromObject(formData.get("parameter"));
                for (Object o : a) {
                    final JSONObject jo;
                    if (o instanceof JSONObject) {
                        jo = (JSONObject) o;
                    } else if (o instanceof JSONNull) {
                        // ignore nulls
                        continue;
                    } else {
                        throw new IllegalArgumentException("Array type is not supported " + o);
                    }
                    String name = jo.getString("name");
                    ParameterDefinition d = manualCondition.getParameterDefinition(name);
                    if (d == null)
                        throw new IllegalArgumentException("No such parameter definition: " + name);
                    paramValues.add(d.createValue(req, jo));
                }
            }
        }
    }
    if (paramValues == null) {
        paramValues = new ArrayList<ParameterValue>();
    }
    Future<Promotion> f = process.scheduleBuild2(target, new UserCause(), paramValues);
    if (f == null)
        LOGGER.warning("Failing to schedule the promotion of " + target);
    // TODO: we need better visual feed back so that the user knows that the build happened.
    rsp.forwardToPreviousPage(req);
}
Also used : ParameterValue(hudson.model.ParameterValue) UserCause(hudson.model.Cause.UserCause) JSONArray(net.sf.json.JSONArray) ManualCondition(hudson.plugins.promoted_builds.conditions.ManualCondition) JSONObject(net.sf.json.JSONObject) JSONNull(net.sf.json.JSONNull) JSONObject(net.sf.json.JSONObject) AbortException(hudson.AbortException) ParameterDefinition(hudson.model.ParameterDefinition) POST(org.kohsuke.stapler.verb.POST)

Example 9 with AbortException

use of hudson.AbortException in project promoted-builds-plugin by jenkinsci.

the class FixedResultBuilder method perform.

@Override
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
    FilePath workspace = build.getWorkspace();
    if (workspace == null) {
        throw new AbortException("Workspace is missing in FixedResultBuilder");
    }
    workspace.child("my.file").write("Hello world!", "UTF-8");
    build.setResult(buildResult);
    return true;
}
Also used : FilePath(hudson.FilePath) AbortException(hudson.AbortException)

Example 10 with AbortException

use of hudson.AbortException in project hudson-2.x by hudson.

the class WindowsInstallerLink method doDoInstall.

/**
 * Performs installation.
 */
public void doDoInstall(StaplerRequest req, StaplerResponse rsp, @QueryParameter("dir") String _dir) throws IOException, ServletException {
    if (installationDir != null) {
        // installation already complete
        sendError("Installation is already complete", req, rsp);
        return;
    }
    if (!DotNet.isInstalled(2, 0)) {
        sendError(".NET Framework 2.0 or later is required for this feature", req, rsp);
        return;
    }
    Hudson.getInstance().checkPermission(Hudson.ADMINISTER);
    File dir = new File(_dir).getAbsoluteFile();
    dir.mkdirs();
    if (!dir.exists()) {
        sendError("Failed to create installation directory: " + dir, req, rsp);
        return;
    }
    try {
        // copy files over there
        copy(req, rsp, dir, getClass().getResource("/windows-service/hudson.exe"), "hudson.exe");
        copy(req, rsp, dir, getClass().getResource("/windows-service/hudson.xml"), "hudson.xml");
        if (!hudsonWar.getCanonicalFile().equals(new File(dir, "hudson.war").getCanonicalFile()))
            copy(req, rsp, dir, hudsonWar.toURI().toURL(), "hudson.war");
        // install as a service
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        StreamTaskListener task = new StreamTaskListener(baos);
        task.getLogger().println("Installing a service");
        int r = WindowsSlaveInstaller.runElevated(new File(dir, "hudson.exe"), "install", task, dir);
        if (r != 0) {
            sendError(baos.toString(), req, rsp);
            return;
        }
        // installation was successful
        installationDir = dir;
        rsp.sendRedirect(".");
    } catch (AbortException e) {
    // this exception is used as a signal to terminate processing. the error should have been already reported
    } catch (InterruptedException e) {
        throw new ServletException(e);
    }
}
Also used : ServletException(javax.servlet.ServletException) StreamTaskListener(hudson.util.StreamTaskListener) ByteArrayOutputStream(org.apache.commons.io.output.ByteArrayOutputStream) File(java.io.File) AbortException(hudson.AbortException)

Aggregations

AbortException (hudson.AbortException)37 IOException (java.io.IOException)13 FilePath (hudson.FilePath)11 EnvVars (hudson.EnvVars)5 ArrayList (java.util.ArrayList)5 Node (hudson.model.Node)4 ArgumentListBuilder (hudson.util.ArgumentListBuilder)4 Launcher (hudson.Launcher)3 Computer (hudson.model.Computer)3 Run (hudson.model.Run)3 WorkspaceList (hudson.slaves.WorkspaceList)3 ServletException (javax.servlet.ServletException)3 StandardCredentials (com.cloudbees.plugins.credentials.common.StandardCredentials)2 AbstractBuild (hudson.model.AbstractBuild)2 ParameterDefinition (hudson.model.ParameterDefinition)2 ParameterValue (hudson.model.ParameterValue)2 PollingResult (hudson.scm.PollingResult)2 SCMRevisionState (hudson.scm.SCMRevisionState)2 File (java.io.File)2 Authentication (org.acegisecurity.Authentication)2