use of org.jenkinsci.plugins.workflow.job.properties.DisableConcurrentBuildsJobProperty in project workflow-job-plugin by jenkinsci.
the class WorkflowJob method setConcurrentBuild.
public void setConcurrentBuild(boolean b) throws IOException {
concurrentBuild = null;
boolean propertyExists = getProperty(DisableConcurrentBuildsJobProperty.class) != null;
// does not exist, we need to add the property. Yay for flipping boolean values around!
if (propertyExists == b) {
BulkChange bc = new BulkChange(this);
try {
removeProperty(DisableConcurrentBuildsJobProperty.class);
if (!b) {
addProperty(new DisableConcurrentBuildsJobProperty());
}
bc.commit();
} finally {
bc.abort();
}
}
}
use of org.jenkinsci.plugins.workflow.job.properties.DisableConcurrentBuildsJobProperty 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();
// cannot override getCharset, and various Run methods do not call it anyway
charset = "UTF-8";
BuildListener myListener = getListener();
myListener.started(getCauses());
Authentication auth = Jenkins.getAuthentication();
if (!auth.equals(ACL.SYSTEM)) {
String name = auth.getName();
if (!auth.equals(Jenkins.ANONYMOUS)) {
User user = User.getById(name, false);
if (user != null) {
name = ModelHyperlinkNote.encodeTo(user);
}
}
myListener.getLogger().println(/* hudson.model.Messages.Run_running_as_(name) */
"Running as " + name);
}
RunListener.fireStarted(this, myListener);
updateSymlinks(myListener);
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, myListener, getAllActions());
if (newExecution instanceof BlockableResume) {
boolean blockResume = getParent().isResumeBlocked();
((BlockableResume) newExecution).setResumeBlocked(blockResume);
if (blockResume) {
myListener.getLogger().println("Resume disabled by user, switching to high-performance, low-durability mode.");
}
}
LOGGER.fine(() -> "Running in Durability level: " + DurabilityHintProvider.suggestedFor(this.project));
// Save before we add to the FlowExecutionList, to ensure we never have a run with a null build.
save();
synchronized (getMetadataGuard()) {
// Technically safe but it makes FindBugs happy
FlowExecutionList.get().register(owner);
newExecution.addListener(new GraphL());
newExecution.addListener(new NodePrintListener());
completed = Boolean.FALSE;
executionLoaded = true;
execution = newExecution;
}
SettableFuture<FlowExecution> exec = getSettableExecutionPromise();
if (!exec.isDone()) {
exec.set(newExecution);
}
FlowExecutionListener.fireCreated(newExecution);
// We should probably have the promise set before beginning, no?
newExecution.start();
FlowExecutionListener.fireRunning(newExecution);
DisableConcurrentBuildsJobProperty dcb = getParent().getProperty(DisableConcurrentBuildsJobProperty.class);
if (dcb != null && dcb.isAbortPrevious()) {
WorkflowRun prev = getPreviousBuild();
if (prev != null && prev.isBuilding()) {
Executor e = prev.getExecutor();
if (e != null) {
e.interrupt(Result.NOT_BUILT, new DisableConcurrentBuildsJobProperty.CancelledCause(this));
}
}
// Not bothering to look for other older builds in progress, since once we turn this on, going forward there should be at most one.
}
} catch (Throwable x) {
// ensures isInProgress returns false
execution = null;
executionLoaded = true;
Executor executor = Executor.currentExecutor();
if (Thread.interrupted() && executor != null) {
if (LOGGER.isLoggable(Level.FINE)) {
// In general, the exception thrown by whatever code noticed that the thread was interrupted is not useful.
LOGGER.log(Level.FINE, this + " was interrupted during startup", x);
}
Result result = executor.abortResult();
Collection<CauseOfInterruption> causes = executor.getCausesOfInterruption();
finish(result, new FlowInterruptedException(result, causes.toArray(new CauseOfInterruption[0])));
} else {
finish(Result.FAILURE, x);
}
try {
SettableFuture<FlowExecution> exec = getSettableExecutionPromise();
if (!exec.isDone()) {
exec.setException(x);
}
} catch (Error e) {
if (e != x) {
// cf. CpsThread.runNextChunk
throw e;
}
}
return;
}
throw sleep();
}
Aggregations