Skip to content
Permalink
Browse files

[FIXED JENKINS-19801] Abort module build when maven build is aborted

  • Loading branch information
olivergondza committed Sep 27, 2013
1 parent 403d8c0 commit 02c6393e1e6e5f2ab14d0fd14348373bc649717d
@@ -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.
*/
@@ -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) {
}
});
}

@@ -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;
@@ -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;

0 comments on commit 02c6393

Please sign in to comment.
You can’t perform that action at this time.