use of org.jenkinsci.plugins.workflow.flow.FlowExecution in project workflow-job-plugin by jenkinsci.
the class WorkflowRun method onLoad.
@Override
protected void onLoad() {
super.onLoad();
if (completed != null) {
throw new IllegalStateException("double onLoad of " + this);
}
FlowExecution fetchedExecution = execution;
if (fetchedExecution != null) {
try {
if (getParent().isResumeBlocked() && execution instanceof BlockableResume) {
((BlockableResume) execution).setResumeBlocked(true);
}
fetchedExecution.onLoad(new Owner(this));
} catch (Exception x) {
LOGGER.log(Level.WARNING, null, x);
// probably too broken to use
execution = null;
}
}
fetchedExecution = execution;
if (fetchedExecution != null) {
fetchedExecution.addListener(new GraphL());
executionPromise.set(fetchedExecution);
if (!fetchedExecution.isComplete()) {
// we've been restarted while we were running. let's get the execution going again.
FlowExecutionListener.fireResumed(fetchedExecution);
try {
OutputStream logger = new FileOutputStream(getLogFile(), true);
listener = new StreamBuildListener(logger, Charset.defaultCharset());
listener.getLogger().println("Resuming build at " + new Date() + " after Jenkins restart");
} catch (IOException x) {
LOGGER.log(Level.WARNING, null, x);
listener = new StreamBuildListener(new NullStream());
}
completed = new AtomicBoolean();
Timer.get().submit(new // JENKINS-31614
Runnable() {
@Override
public void run() {
Queue.getInstance().schedule(new AfterRestartTask(WorkflowRun.this), 0);
}
});
}
}
// only for diagnostics
checkouts(null);
synchronized (LOADING_RUNS) {
// or could just make the value type be WeakReference<WorkflowRun>
LOADING_RUNS.remove(key());
LOADING_RUNS.notifyAll();
}
}
use of org.jenkinsci.plugins.workflow.flow.FlowExecution in project workflow-job-plugin by jenkinsci.
the class WorkflowRun method finish.
/**
* Handles normal build completion (including errors) but also handles the case that the flow did not even start correctly, for example due to an error in {@link FlowExecution#start}.
*/
private void finish(@Nonnull Result r, @CheckForNull Throwable t) {
setResult(r);
duration = Math.max(0, System.currentTimeMillis() - getStartTimeInMillis());
LOGGER.log(Level.INFO, "{0} completed: {1}", new Object[] { toString(), getResult() });
if (listener == null) {
LOGGER.log(Level.WARNING, this + " failed to start", t);
} else {
RunListener.fireCompleted(WorkflowRun.this, listener);
if (t instanceof AbortException) {
listener.error(t.getMessage());
} else if (t instanceof FlowInterruptedException) {
((FlowInterruptedException) t).handle(this, listener);
} else if (t != null) {
// TODO 2.43+ use Functions.printStackTrace
listener.getLogger().println(Functions.printThrowable(t).trim());
}
listener.finished(getResult());
listener.closeQuietly();
}
logsToCopy = null;
try {
save();
} catch (Exception x) {
LOGGER.log(Level.WARNING, "failed to save " + this, x);
}
Timer.get().submit(() -> {
try {
getParent().logRotate();
} catch (Exception x) {
LOGGER.log(Level.WARNING, "failed to perform log rotation after " + this, x);
}
});
onEndBuilding();
if (completed != null) {
synchronized (completed) {
completed.set(true);
}
}
FlowExecutionList.get().unregister(new Owner(this));
try {
StashManager.maybeClearAll(this);
} catch (IOException x) {
LOGGER.log(Level.WARNING, "failed to clean up stashes from " + this, x);
}
FlowExecution exec = getExecution();
if (exec != null) {
FlowExecutionListener.fireCompleted(exec);
}
}
use of org.jenkinsci.plugins.workflow.flow.FlowExecution in project blueocean-plugin by jenkinsci.
the class DownstreamJobListener method onStarted.
@Override
public void onStarted(Run<?, ?> run, TaskListener listener) {
for (BuildUpstreamNodeAction action : run.getActions(BuildUpstreamNodeAction.class)) {
Run triggerRun = Run.fromExternalizableId(action.getUpstreamRunId());
if (triggerRun instanceof WorkflowRun) {
FlowExecution execution = ((WorkflowRun) triggerRun).getExecution();
FlowNode node;
if (execution == null) {
LOGGER.warning("Could not retrieve upstream FlowExecution");
continue;
}
try {
node = execution.getNode(action.getUpstreamNodeId());
} catch (IOException e) {
LOGGER.warning("Could not retrieve upstream node: " + e);
continue;
}
if (node == null) {
LOGGER.warning("Could not retrieve upstream node (null)");
continue;
}
// Add an action on the triggerRun node pointing to the currently executing run
String description = run.getDescription();
if (description == null) {
description = run.getFullDisplayName();
}
Link link = LinkResolver.resolveLink(run);
if (link != null) {
try {
// Also add to the actual trigger node so we can find it later by step
node.addAction(new NodeDownstreamBuildAction(link, description));
node.save();
} catch (IOException e) {
LOGGER.severe("Could not persist node: " + e);
}
}
}
}
}
use of org.jenkinsci.plugins.workflow.flow.FlowExecution in project blueocean-plugin by jenkinsci.
the class PipelineNodeGraphVisitor method getPipelineNodeSteps.
@Override
public List<BluePipelineStep> getPipelineNodeSteps(Link parent) {
FlowExecution execution = run.getExecution();
if (execution == null) {
return Collections.emptyList();
}
PipelineStepVisitor visitor = new PipelineStepVisitor(run, null);
ForkScanner.visitSimpleChunks(execution.getCurrentHeads(), visitor, new StageChunkFinder());
List<BluePipelineStep> steps = new ArrayList<>();
for (FlowNodeWrapper node : visitor.getSteps()) {
steps.add(new PipelineStepImpl(node, parent));
}
return steps;
}
use of org.jenkinsci.plugins.workflow.flow.FlowExecution in project workflow-cps-plugin by jenkinsci.
the class CpsFlowExecution method maybeAutoPersistNode.
/**
* Invoke me to toggle autopersist back on for steps that delay it.
*/
public static void maybeAutoPersistNode(@Nonnull FlowNode node) {
try {
FlowExecution exec = node.getExecution();
if (exec instanceof CpsFlowExecution) {
if (exec.getDurabilityHint().isPersistWithEveryStep()) {
FlowNodeStorage exc = ((CpsFlowExecution) exec).getStorage();
exc.autopersist(node);
}
}
} catch (IOException ioe) {
LOGGER.log(Level.WARNING, "Attempt to persist triggered IOException for node " + node.getId(), ioe);
}
}
Aggregations