Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,15 @@ public boolean process(boolean endOfMatrixBuild) {

private boolean processScripts(boolean endOfMatrixBuild) throws PostBuildScriptException {
@SuppressWarnings("NonShortCircuitBooleanExpression")
boolean everyScriptSuccessful = processScriptFiles(endOfMatrixBuild)
boolean everyScriptSuccessful;
try {
everyScriptSuccessful = processScriptFiles(endOfMatrixBuild)
& processGroovyScripts(endOfMatrixBuild)
& processBuildSteps(endOfMatrixBuild);
} catch (InterruptedException e) {
build.setResult(Result.ABORTED);
return true;
}
return everyScriptSuccessful || failOrUnstable();
}

Expand Down Expand Up @@ -162,7 +168,7 @@ private GroovyScriptPreparer createGroovyScriptPreparer() {
return new GroovyScriptPreparer(logger, workspace, executorFactory);
}

private boolean processBuildSteps(boolean endOfMatrixBuild) throws PostBuildScriptException {
private boolean processBuildSteps(boolean endOfMatrixBuild) throws PostBuildScriptException, InterruptedException {

try {
boolean everyStepSuccessful = true;
Expand All @@ -178,6 +184,8 @@ private boolean processBuildSteps(boolean endOfMatrixBuild) throws PostBuildScri
buildSucceed = buildStep.perform(build, launcher, listener);
} catch (AbortException e) {
buildSucceed = false;
} catch (InterruptedException e) {
throw e; // rethrow so that the project get flagged as cancelled
}
everyStepSuccessful &= buildSucceed;

Expand All @@ -187,7 +195,7 @@ private boolean processBuildSteps(boolean endOfMatrixBuild) throws PostBuildScri
}
}
return everyStepSuccessful;
} catch (IOException | InterruptedException ioe) {
} catch (IOException ioe) {
throw new PostBuildScriptException(ioe);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,16 @@
import java.util.Collections;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.logging.Level;
import org.jenkinsci.plugins.postbuildscript.model.PostBuildStep;
import org.jenkinsci.plugins.postbuildscript.model.Script;
import org.jenkinsci.plugins.postbuildscript.model.ScriptFile;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.Test;
import org.junit.Rule;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.LoggerRule;
import org.jvnet.hudson.test.TestBuilder;
import org.jvnet.hudson.test.junit.jupiter.WithJenkins;

Expand All @@ -47,6 +50,10 @@ public class PostBuildScriptIT {
private TestBuildStep firstBuildStep;
private TestBuildStep secondBuildStep;
private TestAbortingBuildStep abortingBuildStep;
private TestInterruptingBuildStep interruptingBuildStep;

@Rule
public LoggerRule loggerRule = new LoggerRule().record("org.jenkinsci.plugins.postbuildscript", Level.FINEST);

@Test
public void executesShellScriptFile(JenkinsRule jenkinsRule) throws Exception {
Expand Down Expand Up @@ -151,6 +158,19 @@ public void handlesAbortException(JenkinsRule jenkinsRule) throws Exception {
Assertions.assertEquals(0, secondBuildStep.getInvocations());
}

@Test
public void handlesInterruptedException(JenkinsRule jenkinsRule) throws Exception {
givenInterruptingBuildStep();
givenSecondBuildStep();
givenPostBuildStep(true);

whenBuilt(jenkinsRule);

thenNoProblemOccured(jenkinsRule);
thenAbortedBuild();
Assertions.assertEquals(0, secondBuildStep.getInvocations());
}

private void givenSuccessfulFirstBuildStep() {
firstBuildStep = new TestBuildStep(true);
buildSteps.add(firstBuildStep);
Expand All @@ -171,6 +191,11 @@ private void givenAbortingBuildStep() {
buildSteps.add( abortingBuildStep );
}

private void givenInterruptingBuildStep() {
interruptingBuildStep = new TestInterruptingBuildStep();
buildSteps.add( interruptingBuildStep );
}

private void givenPostBuildStep(boolean stopOnFailure) {
PostBuildStep step = new PostBuildStep(SUCCESS_RESULTS, buildSteps, stopOnFailure);
Collection<PostBuildStep> steps = Collections.singleton(step);
Expand Down Expand Up @@ -214,6 +239,10 @@ private void thenFailedBuild() {
assertThat(build.getResult(), is(Result.FAILURE));
}

private void thenAbortedBuild() {
assertThat(build.getResult(), is(Result.ABORTED));
}

private void thenNoProblemOccured(JenkinsRule jenkinsRule) throws IOException {
jenkinsRule.assertLogNotContains(Messages.PostBuildScript_ProblemOccured(), build);
}
Expand Down Expand Up @@ -245,4 +274,14 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen
}

}

private static class TestInterruptingBuildStep extends TestBuilder {

@Override
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException {
throw new InterruptedException();
}

}

}