Skip to content

Commit

Permalink
[JENKINS-13554] Do not keep locked builds
Browse files Browse the repository at this point in the history
  • Loading branch information
olivergondza committed Jan 4, 2015
1 parent 4e22a02 commit 815b8d0
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
3 changes: 0 additions & 3 deletions src/main/java/hudson/matrix/MatrixBuild.java
Expand Up @@ -93,16 +93,13 @@ public Object readResolve() {
/**
* Delete build and its child builds.
*
* Child builds can be skipped if they have to be kept.
*
* @since TODO
*/
@Override
public void delete() throws IOException {
super.delete();

for(MatrixRun run : getExactRuns()) {
if (run.getWhyKeepLog() != null) continue;
run.delete();
}
}
Expand Down
37 changes: 35 additions & 2 deletions src/test/groovy/hudson/matrix/MatrixProjectTest.groovy
Expand Up @@ -559,7 +559,40 @@ public class MatrixProjectTest {
assertThat(build.getWorkspace().getRemote(), containsString("/workspace/shortName/${build.parent.digestName}"));
}

@Test
@Test @Issue("JENKINS-13554")
public void deletedLockedParentBuild() {
MatrixProject p = j.jenkins.createProject(MatrixProject.class, "project");
p.setAxes(new AxisList(new TextAxis("AXIS", "VALUE")));
def build = p.scheduleBuild2(0).get();
def c = p.getItem("AXIS=VALUE");

build.keepLog();

build.delete();

assertEquals("parent build is deleted", 0, p.builds.size());
assertEquals("child build is deleted", 0, c.builds.size());
}

@Test @Issue("JENKINS-13554")
public void deletedParentBuildWithLockedChildren() {
MatrixProject p = j.jenkins.createProject(MatrixProject.class, "project");
p.setAxes(new AxisList(new TextAxis("AXIS", "VALUE")));
def build = p.scheduleBuild2(0).get();
p.scheduleBuild2(0).get();

def c = p.getItem("AXIS=VALUE");

c.getBuildByNumber(2).delete(); // delete newest run
assertNotNull(c.getBuildByNumber(1).getWhyKeepLog());

build.delete();

assertEquals("last parent build should be kept", 1, p.builds.size());
assertEquals("child builds are deleted", 0, c.builds.size());
}

@Test @Issue("JENKINS-13554")
public void discardBuilds() {
MatrixProject p = j.jenkins.createProject(MatrixProject.class, "discarder");
p.setAxes(new AxisList(new TextAxis("AXIS", "VALUE")));
Expand Down Expand Up @@ -600,7 +633,7 @@ public class MatrixProjectTest {
assertEquals(1, last.artifacts.size());
}

@Test
@Test @Issue("JENKINS-13554")
public void deleteBuildWithChildrenOverCLI() {
MatrixProject p = j.jenkins.createProject(MatrixProject.class, "project");
p.setAxes(new AxisList(new TextAxis("AXIS", "VALUE")));
Expand Down

0 comments on commit 815b8d0

Please sign in to comment.