提交 5ed111f0 编写于 作者: R Ryan Campbell 提交者: Oliver Gondža

[JENKINS-26718] Allow runs to be discarded even if their project can't be found by its fullname

(cherry picked from commit 327f7780)
上级 dc68946f
......@@ -355,10 +355,12 @@ public class OldDataMonitor extends AdministrativeMonitor {
private static SaveableReference referTo(Saveable s) {
if (s instanceof Run) {
return new RunSaveableReference((Run) s);
} else {
return new SimpleSaveableReference(s);
Job parent = ((Run) s).getParent();
if (Jenkins.getInstance().getItemByFullName(parent.getFullName()) == parent) {
return new RunSaveableReference((Run) s);
}
}
return new SimpleSaveableReference(s);
}
private static final class SimpleSaveableReference implements SaveableReference {
......
......@@ -41,11 +41,16 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import hudson.model.ItemGroup;
import hudson.model.Job;
import hudson.model.Run;
import hudson.model.Saveable;
import hudson.model.listeners.SaveableListener;
import jenkins.model.Jenkins;
import jenkins.model.lazy.BuildReference;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
......@@ -56,6 +61,8 @@ import org.jvnet.hudson.test.MemoryAssert;
import org.jvnet.hudson.test.recipes.LocalData;
import org.kohsuke.stapler.Stapler;
import javax.annotation.Nonnull;
public class OldDataMonitorTest {
static {
......@@ -149,6 +156,21 @@ public class OldDataMonitorTest {
}
@Issue("JENKINS-26718")
@Test public void unlocatableRun() throws Exception {
OldDataMonitor odm = OldDataMonitor.get(r.jenkins);
FreeStyleProject p = mock(FreeStyleProject.class);
when(p.getParent()).thenReturn(Jenkins.getInstance());
when(p.getFullName()).thenReturn("notfound");
FreeStyleBuild build = new FreeStyleBuild(p);
odm.report(build, (String) null);
assertEquals(Collections.singleton(build), odm.getData().keySet());
odm.doDiscard(null, null);
assertEquals(Collections.emptySet(), odm.getData().keySet());
}
public static final class BadAction extends InvisibleAction {
private Object writeReplace() {
throw new IllegalStateException("broken");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册