mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-10-26 19:15:09 +00:00
Update a single InterruptedBuildAction rather than creating a second one (#10610)
This commit is contained in:
2 files changed
+42
-1
No files matched your search
@@ -50,6 +50,7 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
import java.util.concurrent.Callable;
|
||||
@@ -284,7 +285,14 @@ public class Executor extends Thread implements ModelObject, IExecutor {
|
||||
lock.writeLock().unlock();
|
||||
}
|
||||
|
||||
build.addAction(new InterruptedBuildAction(r));
|
||||
InterruptedBuildAction action = build.getAction(InterruptedBuildAction.class);
|
||||
if (action != null) {
|
||||
Collection<CauseOfInterruption> combinedCauses = new LinkedHashSet<>(action.getCauses());
|
||||
combinedCauses.addAll(r);
|
||||
build.replaceAction(new InterruptedBuildAction(combinedCauses));
|
||||
} else {
|
||||
build.addAction(new InterruptedBuildAction(r));
|
||||
}
|
||||
for (CauseOfInterruption c : r)
|
||||
c.print(listener);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package hudson.model;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.allOf;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
@@ -16,7 +17,9 @@ import hudson.slaves.DumbSlave;
|
||||
import hudson.slaves.OfflineCause;
|
||||
import hudson.util.OneShotEvent;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import jenkins.model.CauseOfInterruption;
|
||||
import jenkins.model.CauseOfInterruption.UserInterruption;
|
||||
import jenkins.model.InterruptedBuildAction;
|
||||
import jenkins.model.Jenkins;
|
||||
@@ -227,4 +230,34 @@ public class ExecutorTest {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void recordCauseOfInterruption() throws Exception {
|
||||
FreeStyleProject p = j.createFreeStyleProject();
|
||||
p.getBuildersList().add(TestBuilder.of((build, launcher, listener) -> {
|
||||
Executor exec = build.getExecutor();
|
||||
exec.interrupt(Result.NOT_BUILT, new TestCauseOfInterruption("one"), new TestCauseOfInterruption("two"));
|
||||
exec.recordCauseOfInterruption(build, listener);
|
||||
exec.interrupt(Result.NOT_BUILT, new TestCauseOfInterruption("three"), new TestCauseOfInterruption("four"));
|
||||
exec.recordCauseOfInterruption(build, listener);
|
||||
}));
|
||||
FreeStyleBuild b = j.buildAndAssertStatus(Result.NOT_BUILT, p);
|
||||
assertThat(b.getActions(InterruptedBuildAction.class).stream().map(iba -> iba.getCauses().stream().map(CauseOfInterruption::getShortDescription).toList()).toList(), is(List.of(List.of("one", "two", "three", "four"))));
|
||||
}
|
||||
|
||||
private static final class TestCauseOfInterruption extends CauseOfInterruption {
|
||||
private final String msg;
|
||||
|
||||
TestCauseOfInterruption(String msg) {
|
||||
this.msg = msg;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getShortDescription() {
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user