Search in sources :

Example 26 with FlowExecution

use of org.jenkinsci.plugins.workflow.flow.FlowExecution 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)

Example 27 with FlowExecution

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

the class FlowGraphAction method getNodes.

@Exported
public Collection<? extends FlowNode> getNodes() {
    FlowExecution exec = run.getExecution();
    if (exec == null) {
        return Collections.emptySet();
    }
    List<FlowNode> nodes = new ArrayList<>();
    FlowGraphWalker walker = new FlowGraphWalker(exec);
    for (FlowNode n : walker) {
        nodes.add(n);
    }
    Collections.reverse(nodes);
    return nodes;
}
Also used : FlowExecution(org.jenkinsci.plugins.workflow.flow.FlowExecution) ArrayList(java.util.ArrayList) FlowGraphWalker(org.jenkinsci.plugins.workflow.graph.FlowGraphWalker) FlowNode(org.jenkinsci.plugins.workflow.graph.FlowNode) Exported(org.kohsuke.stapler.export.Exported)

Example 28 with FlowExecution

use of org.jenkinsci.plugins.workflow.flow.FlowExecution in project selenium_java by sergueik.

the class Audit2DbGraphListener method onNewHead.

@Override
public void onNewHead(FlowNode node) {
    if (!FlowEndNode.class.isInstance(node)) {
        return;
    }
    LOGGER.fine("Found the FlowEndNode.");
    FlowExecution execution = node.getExecution();
    LOGGER.fine("FlowExecution.isComplete: " + execution.isComplete());
    if (!CpsFlowExecution.class.isInstance(execution)) {
        throw new IllegalStateException("Cannot get a pipeline result from a FlowExecution that is not an instance of CpsFlowExecution: " + execution.getClass().getName());
    }
    CpsFlowExecution cpsFlowExecution = (CpsFlowExecution) execution;
    LOGGER.fine("CpsFlowExecution.result: " + cpsFlowExecution.getResult());
    BuildDetailsResolver.updateResultAndEndTime(details, cpsFlowExecution, new Date());
    LOGGER.fine("Persisting BuildDetails");
    repository.saveBuildDetails(details);
    LOGGER.fine("Audit2DbGraphListener.onNewHead(): complete");
}
Also used : CpsFlowExecution(org.jenkinsci.plugins.workflow.cps.CpsFlowExecution) FlowExecution(org.jenkinsci.plugins.workflow.flow.FlowExecution) FlowEndNode(org.jenkinsci.plugins.workflow.graph.FlowEndNode) CpsFlowExecution(org.jenkinsci.plugins.workflow.cps.CpsFlowExecution) Date(java.util.Date)

Aggregations

FlowExecution (org.jenkinsci.plugins.workflow.flow.FlowExecution)28 WorkflowRun (org.jenkinsci.plugins.workflow.job.WorkflowRun)10 FlowNode (org.jenkinsci.plugins.workflow.graph.FlowNode)9 Test (org.junit.Test)9 ArrayList (java.util.ArrayList)7 Statement (org.junit.runners.model.Statement)7 Jenkins (jenkins.model.Jenkins)6 FlowExecutionOwner (org.jenkinsci.plugins.workflow.flow.FlowExecutionOwner)6 AbortException (hudson.AbortException)5 IOException (java.io.IOException)5 CpsFlowExecution (org.jenkinsci.plugins.workflow.cps.CpsFlowExecution)4 DepthFirstScanner (org.jenkinsci.plugins.workflow.graphanalysis.DepthFirstScanner)4 FlowInterruptedException (org.jenkinsci.plugins.workflow.steps.FlowInterruptedException)3 LineTransformationOutputStream (hudson.console.LineTransformationOutputStream)2 StreamBuildListener (hudson.model.StreamBuildListener)2 CopyOnWriteList (hudson.util.CopyOnWriteList)2 BluePipelineStep (io.jenkins.blueocean.rest.model.BluePipelineStep)2 FileOutputStream (java.io.FileOutputStream)2 OutputStream (java.io.OutputStream)2 Date (java.util.Date)2