Search in sources :

Example 26 with AbortException

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

the class CpsFlowExecution method loadProgramFailed.

/**
 * Used by {@link #loadProgramAsync(File)} to propagate a failure to load the persisted execution state.
 * <p>
 * Let the workflow interrupt by throwing an exception that indicates how it failed.
 * @param promise same as {@link #programPromise} but more strongly typed
 */
private void loadProgramFailed(final Throwable problem, SettableFuture<CpsThreadGroup> promise) {
    FlowHead head;
    synchronized (this) {
        if (heads == null || heads.isEmpty()) {
            head = null;
        } else {
            head = getFirstHead();
        }
    }
    if (head == null) {
        // something went catastrophically wrong and there's no live head. fake one
        head = new FlowHead(this);
        try {
            head.newStartNode(new FlowStartNode(this, iotaStr()));
        } catch (IOException e) {
            LOGGER.log(Level.FINE, "Failed to persist", e);
        }
    }
    CpsThreadGroup g = new CpsThreadGroup(this);
    final FlowHead head_ = head;
    promise.set(g);
    runInCpsVmThread(new FutureCallback<CpsThreadGroup>() {

        @Override
        public void onSuccess(CpsThreadGroup g) {
            CpsThread t = g.addThread(new Continuable(new ThrowBlock(new ConstantBlock(problem instanceof AbortException ? problem : new IOException("Failed to load build state", problem)))), head_, null);
            t.resume(new Outcome(null, null));
        }

        @Override
        public void onFailure(Throwable t) {
            LOGGER.log(Level.WARNING, "Failed to set program failure on " + owner, t);
            croak(t);
        }
    });
}
Also used : FlowStartNode(org.jenkinsci.plugins.workflow.graph.FlowStartNode) ThrowBlock(com.cloudbees.groovy.cps.impl.ThrowBlock) IOException(java.io.IOException) ConstantBlock(com.cloudbees.groovy.cps.impl.ConstantBlock) Outcome(com.cloudbees.groovy.cps.Outcome) Continuable(com.cloudbees.groovy.cps.Continuable) AbortException(hudson.AbortException)

Example 27 with AbortException

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

the class CpsFlowExecutionTest method getCurrentExecutions.

@Test
public void getCurrentExecutions() {
    story.addStep(new Statement() {

        @Override
        public void evaluate() throws Throwable {
            WorkflowJob p = story.j.jenkins.createProject(WorkflowJob.class, "p");
            p.setDefinition(new CpsFlowDefinition("echo 'a step'; semaphore 'one'; retry(2) {semaphore 'two'; node {semaphore 'three'}; semaphore 'four'}; semaphore 'five'; " + "parallel a: {node {semaphore 'six'}}, b: {semaphore 'seven'}; semaphore 'eight'", true));
            WorkflowRun b = p.scheduleBuild2(0).waitForStart();
            SemaphoreStep.waitForStart("one/1", b);
            FlowExecution e = b.getExecution();
            assertStepExecutions(e, "semaphore");
            SemaphoreStep.success("one/1", null);
            SemaphoreStep.waitForStart("two/1", b);
            assertStepExecutions(e, "retry {}", "semaphore");
            SemaphoreStep.success("two/1", null);
            SemaphoreStep.waitForStart("three/1", b);
            assertStepExecutions(e, "retry {}", "node {}", "semaphore");
        }
    });
    story.addStep(new Statement() {

        @Override
        public void evaluate() throws Throwable {
            WorkflowJob p = story.j.jenkins.getItemByFullName("p", WorkflowJob.class);
            WorkflowRun b = p.getLastBuild();
            CpsFlowExecution e = (CpsFlowExecution) b.getExecution();
            assertTrue(e.isSandbox());
            SemaphoreStep.success("three/1", null);
            SemaphoreStep.waitForStart("four/1", b);
            assertStepExecutions(e, "retry {}", "semaphore");
            SemaphoreStep.failure("four/1", new AbortException("try again"));
            SemaphoreStep.waitForStart("two/2", b);
            assertStepExecutions(e, "retry {}", "semaphore");
            SemaphoreStep.success("two/2", null);
            SemaphoreStep.waitForStart("three/2", b);
            assertStepExecutions(e, "retry {}", "node {}", "semaphore");
            SemaphoreStep.success("three/2", null);
            SemaphoreStep.waitForStart("four/2", b);
            assertStepExecutions(e, "retry {}", "semaphore");
            SemaphoreStep.success("four/2", null);
            SemaphoreStep.waitForStart("five/1", b);
            assertStepExecutions(e, "semaphore");
            SemaphoreStep.success("five/1", null);
            SemaphoreStep.waitForStart("six/1", b);
            SemaphoreStep.waitForStart("seven/1", b);
            assertStepExecutions(e, "parallel {}", "node {}", "semaphore", "semaphore");
            SemaphoreStep.success("six/1", null);
            SemaphoreStep.success("seven/1", null);
            SemaphoreStep.waitForStart("eight/1", b);
            assertStepExecutions(e, "semaphore");
            SemaphoreStep.success("eight/1", null);
            story.j.assertBuildStatusSuccess(story.j.waitForCompletion(b));
            assertStepExecutions(e);
        }
    });
}
Also used : Statement(org.junit.runners.model.Statement) FlowExecution(org.jenkinsci.plugins.workflow.flow.FlowExecution) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) AbortException(hudson.AbortException) Test(org.junit.Test)

Example 28 with AbortException

use of hudson.AbortException 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 29 with AbortException

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

the class PublishHTMLStepExecution method run.

@Override
protected Void run() throws Exception {
    final HtmlPublisherTarget target = step.getTarget();
    if (target == null) {
        throw new AbortException("Cannot publish the report. Target is not specified");
    }
    boolean res = HtmlPublisher.publishReports(getContext().get(Run.class), getContext().get(FilePath.class), getContext().get(TaskListener.class), Collections.singletonList(target), HtmlPublisher.class);
    if (!res) {
        throw new AbortException("Cannot publish HTML files");
    }
    return null;
}
Also used : FilePath(hudson.FilePath) HtmlPublisherTarget(htmlpublisher.HtmlPublisherTarget) TaskListener(hudson.model.TaskListener) Run(hudson.model.Run) AbortException(hudson.AbortException)

Example 30 with AbortException

use of hudson.AbortException in project sonar-scanner-jenkins by SonarSource.

the class MsBuildSQRunnerBegin method perform.

@Override
public void perform(Run<?, ?> run, FilePath workspace, Launcher launcher, TaskListener listener) throws InterruptedException, IOException {
    ArgumentListBuilder args = new ArgumentListBuilder();
    EnvVars env = BuilderUtils.getEnvAndBuildVars(run, listener);
    SonarInstallation sonarInstallation = getSonarInstallation(getSonarInstallationName(), listener);
    MsBuildSQRunnerInstallation msBuildScanner = getDescriptor().getMsBuildScannerInstallation(msBuildScannerInstallationName);
    run.addAction(new SonarQubeScannerMsBuildParams(msBuildScannerInstallationName, getSonarInstallationName()));
    args.add(getExeName(msBuildScanner, env, launcher, listener, workspace));
    Map<String, String> props = getSonarProps(sonarInstallation);
    addArgsTo(args, sonarInstallation, env, props);
    int result = launcher.launch().cmds(args).envs(env).stdout(listener).pwd(BuilderUtils.getModuleRoot(run, workspace)).join();
    if (result != 0) {
        throw new AbortException(Messages.MSBuildScanner_ExecFailed(result));
    }
}
Also used : EnvVars(hudson.EnvVars) ArgumentListBuilder(hudson.util.ArgumentListBuilder) 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