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);
}
});
}
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);
}
});
}
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();
}
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;
}
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));
}
}
Aggregations