Search in sources :

Example 1 with FlowDefinition

use of org.jenkinsci.plugins.workflow.flow.FlowDefinition in project workflow-job-plugin by jenkinsci.

the class WorkflowRun method run.

/**
 * Actually executes the workflow.
 */
@Override
public void run() {
    if (!firstTime) {
        throw sleep();
    }
    try {
        onStartBuilding();
        OutputStream logger = new FileOutputStream(getLogFile());
        listener = new StreamBuildListener(logger, Charset.defaultCharset());
        listener.started(getCauses());
        Authentication auth = Jenkins.getAuthentication();
        if (!auth.equals(ACL.SYSTEM)) {
            String name = auth.getName();
            if (!auth.equals(Jenkins.ANONYMOUS)) {
                name = ModelHyperlinkNote.encodeTo(User.get(name));
            }
            listener.getLogger().println(hudson.model.Messages.Run_running_as_(name));
        }
        RunListener.fireStarted(this, listener);
        updateSymlinks(listener);
        FlowDefinition definition = getParent().getDefinition();
        if (definition == null) {
            throw new AbortException("No flow definition, cannot run");
        }
        Owner owner = new Owner(this);
        FlowExecution newExecution = definition.create(owner, listener, getAllActions());
        boolean loggedHintOverride = false;
        if (getParent().isResumeBlocked()) {
            if (newExecution instanceof BlockableResume) {
                ((BlockableResume) newExecution).setResumeBlocked(true);
                listener.getLogger().println("Resume disabled by user, switching to high-performance, low-durability mode.");
                loggedHintOverride = true;
            }
        }
        if (!loggedHintOverride) {
            // Avoid double-logging
            listener.getLogger().println("Running in Durability level: " + DurabilityHintProvider.suggestedFor(this.project));
        }
        FlowExecutionList.get().register(owner);
        newExecution.addListener(new GraphL());
        completed = new AtomicBoolean();
        logsToCopy = new ConcurrentSkipListMap<>();
        execution = newExecution;
        newExecution.start();
        executionPromise.set(newExecution);
        FlowExecutionListener.fireRunning(execution);
    } catch (Throwable x) {
        // ensures isInProgress returns false
        execution = null;
        finish(Result.FAILURE, x);
        try {
            executionPromise.setException(x);
        } catch (Error e) {
            if (e != x) {
                // cf. CpsThread.runNextChunk
                throw e;
            }
        }
        return;
    }
    throw sleep();
}
Also used : FlowExecutionOwner(org.jenkinsci.plugins.workflow.flow.FlowExecutionOwner) LineTransformationOutputStream(hudson.console.LineTransformationOutputStream) FileOutputStream(java.io.FileOutputStream) OutputStream(java.io.OutputStream) StreamBuildListener(hudson.model.StreamBuildListener) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Authentication(org.acegisecurity.Authentication) FileOutputStream(java.io.FileOutputStream) FlowExecution(org.jenkinsci.plugins.workflow.flow.FlowExecution) FlowDefinition(org.jenkinsci.plugins.workflow.flow.FlowDefinition) BlockableResume(org.jenkinsci.plugins.workflow.flow.BlockableResume) AbortException(hudson.AbortException)

Aggregations

AbortException (hudson.AbortException)1 LineTransformationOutputStream (hudson.console.LineTransformationOutputStream)1 StreamBuildListener (hudson.model.StreamBuildListener)1 FileOutputStream (java.io.FileOutputStream)1 OutputStream (java.io.OutputStream)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Authentication (org.acegisecurity.Authentication)1 BlockableResume (org.jenkinsci.plugins.workflow.flow.BlockableResume)1 FlowDefinition (org.jenkinsci.plugins.workflow.flow.FlowDefinition)1 FlowExecution (org.jenkinsci.plugins.workflow.flow.FlowExecution)1 FlowExecutionOwner (org.jenkinsci.plugins.workflow.flow.FlowExecutionOwner)1