Skip to content

Commit

Permalink
[FIXED JENKINS-19801] Abort module build when maven build is aborted
Browse files Browse the repository at this point in the history
  • Loading branch information
olivergondza committed Sep 27, 2013
1 parent 403d8c0 commit 02c6393
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 8 deletions.
9 changes: 9 additions & 0 deletions core/src/main/java/hudson/model/Run.java
Expand Up @@ -465,6 +465,15 @@ public boolean isBuilding() {
return state.compareTo(State.POST_PRODUCTION) < 0;
}

/**
* Determine whether the run is being build right now.
* @return true if after started and before completed.
* @since TODO
*/
protected boolean isInProgress() {
return state.equals(State.BUILDING);
}

/**
* Returns true if the log file is still being updated.
*/
Expand Down
24 changes: 17 additions & 7 deletions maven-plugin/src/main/java/hudson/maven/MavenBuild.java
Expand Up @@ -613,22 +613,32 @@ protected void close() {
e.printStackTrace();
}

abstract class Terminate extends RunExecution {
@Override public void post(BuildListener listener) {}
@Override public void cleanUp(BuildListener listener) {}
}

if(isInProgress()) {
// Build was aborted, abort run as well.
MavenBuild.this.execute(new Terminate() {
@Override
public Result run(BuildListener listener) {
return Result.ABORTED;
}
});
}

if(hasntStartedYet()) {
// Mark the build as not_built. This method is used when the aggregated build
// failed before it didn't even get to this module
// OR if the aggregated build is an incremental one and this
// module needn't be build.
MavenBuild.this.execute(new RunExecution() {
MavenBuild.this.execute(new Terminate() {
@Override
public Result run(BuildListener listener) {
listener.getLogger().println(Messages.MavenBuild_FailedEarlier());
return Result.NOT_BUILT;
}

public void post(BuildListener listener) {
}

public void cleanUp(BuildListener listener) {
}
});
}

Expand Down
36 changes: 35 additions & 1 deletion test/src/test/java/hudson/maven/MavenBuildTest.java
Expand Up @@ -5,6 +5,7 @@
import hudson.model.ParametersDefinitionProperty;
import hudson.model.Result;
import hudson.model.StringParameterDefinition;
import hudson.model.queue.QueueTaskFuture;
import hudson.tasks.Maven.MavenInstallation;
import hudson.tasks.test.AbstractTestResultAction;
import hudson.tasks.test.AggregatedTestResultAction;
Expand Down Expand Up @@ -190,7 +191,40 @@ public void testExtensionsConflictingWithCore() throws Exception {
"</extensions></build></project>"));
buildAndAssertSuccess(m);
}


@Bug(19801)
public void tetStopBuildAndAllSubmoduleBuilds() throws Exception {
configureDefaultMaven();
MavenModuleSet project = createMavenProject();
project.setGoals("clean package");
project.setScm(new ExtractResourceSCM(
getClass().getResource("/hudson/maven/maven-multimod.zip")
));

MavenModuleSetBuild build = project.scheduleBuild2(0).waitForStart();

ensureSubmoduleBuildsStarted(build);

build.doStop();

Thread.sleep(2000);
assertBuildStatus(Result.ABORTED, build);
assertFalse(build.isBuilding());
for (MavenBuild mb: build.getModuleLastBuilds().values()) {
final String moduleName = mb.getParent().getDisplayName();
assertFalse("Module " + moduleName + " is still building", mb.isBuilding());
}
}

private void ensureSubmoduleBuildsStarted(MavenModuleSetBuild build) throws InterruptedException {
for (;;) {
for (MavenBuild mb: build.getModuleLastBuilds().values()) {
if (Result.SUCCESS.equals(mb.getResult())) return;
}
Thread.sleep(1000);
}
}

private static class TestReporter extends MavenReporter {
private static final long serialVersionUID = 1L;

Expand Down

0 comments on commit 02c6393

Please sign in to comment.