Search in sources :

Example 1 with ConsoleLogFilter

use of hudson.console.ConsoleLogFilter in project hudson-2.x by hudson.

the class Run method run.

protected final void run(Runner job) {
    if (result != null)
        // already built.
        return;
    StreamBuildListener listener = null;
    runner = job;
    onStartBuilding();
    try {
        // to set the state to COMPLETE in the end, even if the thread dies abnormally.
        // otherwise the queue state becomes inconsistent
        long start = System.currentTimeMillis();
        try {
            try {
                Charset charset = Computer.currentComputer().getDefaultCharset();
                this.charset = charset.name();
                // don't do buffering so that what's written to the listener
                // gets reflected to the file immediately, which can then be
                // served to the browser immediately
                OutputStream logger = new FileOutputStream(getLogFile());
                RunT build = job.getBuild();
                // Global log filters
                for (ConsoleLogFilter filter : ConsoleLogFilter.all()) {
                    logger = filter.decorateLogger((AbstractBuild) build, logger);
                }
                // Project specific log filterss
                if (project instanceof BuildableItemWithBuildWrappers && build instanceof AbstractBuild) {
                    BuildableItemWithBuildWrappers biwbw = (BuildableItemWithBuildWrappers) project;
                    for (BuildWrapper bw : biwbw.getBuildWrappersList()) {
                        logger = bw.decorateLogger((AbstractBuild) build, logger);
                    }
                }
                listener = new StreamBuildListener(logger, charset);
                listener.started(getCauses());
                RunListener.fireStarted(this, listener);
                // create a symlink from build number to ID.
                Util.createSymlink(getParent().getBuildDir(), getId(), String.valueOf(getNumber()), listener);
                setResult(job.run(listener));
                LOGGER.info(toString() + " main build action completed: " + result);
                CheckPoint.MAIN_COMPLETED.report();
            } catch (ThreadDeath t) {
                throw t;
            } catch (AbortException e) {
                // orderly abortion.
                result = Result.FAILURE;
                listener.error(e.getMessage());
                LOGGER.log(FINE, "Build " + this + " aborted", e);
            } catch (RunnerAbortedException e) {
                // orderly abortion.
                result = Result.FAILURE;
                LOGGER.log(FINE, "Build " + this + " aborted", e);
            } catch (InterruptedException e) {
                // aborted
                result = Result.ABORTED;
                listener.getLogger().println(Messages.Run_BuildAborted());
                LOGGER.log(Level.INFO, toString() + " aborted", e);
            } catch (Throwable e) {
                handleFatalBuildProblem(listener, e);
                result = Result.FAILURE;
            }
            // even if the main build fails fatally, try to run post build processing
            job.post(listener);
        } catch (ThreadDeath t) {
            throw t;
        } catch (Throwable e) {
            handleFatalBuildProblem(listener, e);
            result = Result.FAILURE;
        } finally {
            long end = System.currentTimeMillis();
            // @see HUDSON-5844
            duration = Math.max(end - start, 0);
            // advance the state.
            // the significance of doing this is that Hudson
            // will now see this build as completed.
            // things like triggering other builds requires this as pre-condition.
            // see issue #980.
            state = State.POST_PRODUCTION;
            try {
                job.cleanUp(listener);
            } catch (Exception e) {
                handleFatalBuildProblem(listener, e);
            // too late to update the result now
            }
            RunListener.fireCompleted(this, listener);
            if (listener != null)
                listener.finished(result);
            if (listener != null)
                listener.closeQuietly();
            try {
                save();
            } catch (IOException e) {
                LOGGER.log(Level.SEVERE, "Failed to save build record", e);
            }
        }
        try {
            getParent().logRotate();
        } catch (IOException e) {
            LOGGER.log(Level.SEVERE, "Failed to rotate log", e);
        } catch (InterruptedException e) {
            LOGGER.log(Level.SEVERE, "Failed to rotate log", e);
        }
    } finally {
        onEndBuilding();
    }
}
Also used : OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FlushProofOutputStream(hudson.util.FlushProofOutputStream) Charset(java.nio.charset.Charset) IOException(java.io.IOException) ServletException(javax.servlet.ServletException) ParseException(java.text.ParseException) FormException(hudson.model.Descriptor.FormException) AbortException(hudson.AbortException) IOException(java.io.IOException) ConsoleLogFilter(hudson.console.ConsoleLogFilter) FileOutputStream(java.io.FileOutputStream) BuildWrapper(hudson.tasks.BuildWrapper) AbortException(hudson.AbortException)

Aggregations

AbortException (hudson.AbortException)1 ConsoleLogFilter (hudson.console.ConsoleLogFilter)1 FormException (hudson.model.Descriptor.FormException)1 BuildWrapper (hudson.tasks.BuildWrapper)1 FlushProofOutputStream (hudson.util.FlushProofOutputStream)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 Charset (java.nio.charset.Charset)1 ParseException (java.text.ParseException)1 ServletException (javax.servlet.ServletException)1