Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ public void stop(@NonNull Throwable cause) throws Exception {
} else {
LOGGER.warning(() -> "failed to cancel " + item + " in response to " + cause);
}
// TODO RunningTasks.remove(context) ?
break;
} else {
LOGGER.log(FINE, "no match on {0} with {1} vs. {2}", new Object[] {item, task.context, context});
Expand Down Expand Up @@ -1223,7 +1224,12 @@ public static class RunningTasks {
static void add(StepContext context) {
RunningTasks holder = ExtensionList.lookupSingleton(RunningTasks.class);
synchronized (holder) {
holder.runningTasks.putIfAbsent(context, new RunningTask());
RunningTask existing = holder.runningTasks.putIfAbsent(context, new RunningTask());
if (existing == null) {
LOGGER.fine(() -> "registered new RunningTask for " + context);
} else {
LOGGER.warning(() -> context + " already had a RunningTask");
}
}
}

Expand Down Expand Up @@ -1260,7 +1266,10 @@ static void run(StepContext context, Consumer<RunningTask> fn) {
static void remove(StepContext context) {
RunningTasks holder = ExtensionList.lookupSingleton(RunningTasks.class);
synchronized (holder) {
if (holder.runningTasks.remove(context) == null) {
if (holder.runningTasks.remove(context) != null) {
LOGGER.fine(() -> "removed RunningTask for " + context);
Thread.dumpStack();//TODO
} else {
LOGGER.fine(() -> "no RunningTask to remove associated with " + context);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1228,6 +1228,25 @@ public void getOwnerTaskPermissions() throws Throwable {
});
}

@Issue("JENKINS-60507")
@Test public void recreateJob() throws Throwable {
Assume.assumeFalse(useWatching); // irrelevant here
sessions.then(r -> {
logging.record(ExecutorStepExecution.class, Level.FINE);
WorkflowJob p = r.createProject(WorkflowJob.class, "p");
p.setDefinition(new CpsFlowDefinition("node('nonexistent') {}", true));
WorkflowRun b = p.scheduleBuild2(0).waitForStart();
assertTrue(Queue.getInstance().cancel(await().until(
() -> Stream.of(Queue.getInstance().getItems()).filter(i -> i.task instanceof ExecutorStepExecution.PlaceholderTask && i.task.getOwnerTask() == p).
findFirst().orElse(null), notNullValue())));
r.assertBuildStatus(Result.ABORTED, r.waitForCompletion(b));
p.delete();
WorkflowJob p2 = r.createProject(WorkflowJob.class, "p");
p2.setDefinition(new CpsFlowDefinition("node {}", true));
r.buildAndAssertSuccess(p2);
});
}

private static class MainAuthenticator extends QueueItemAuthenticator {
@Override public Authentication authenticate(Queue.Task task) {
return task instanceof WorkflowJob ? User.getById("dev", true).impersonate() : null;
Expand Down