Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JENKINS-60354] Use FlowInterruptedException.isActualInterruption to decide if an exception should be rethrown #102

Merged
merged 3 commits into from
Jan 3, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 8 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
<changelist>-SNAPSHOT</changelist>
<jenkins.version>2.150.1</jenkins.version>
<java.level>8</java.level>
<workflow-step-api-plugin.version>2.20</workflow-step-api-plugin.version>
<workflow-step-api-plugin.version>2.22-20191211.162318-1</workflow-step-api-plugin.version> <!-- TODO: https://github.com/jenkinsci/workflow-step-api-plugin/pull/51 -->
<workflow-cps-plugin.version>2.70</workflow-cps-plugin.version>
<workflow-support-plugin.version>3.3</workflow-support-plugin.version>
<workflow-api-plugin.version>2.34</workflow-api-plugin.version>
Expand Down Expand Up @@ -100,7 +100,7 @@
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>structs</artifactId>
<version>1.18</version>
<version>1.20</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
Expand Down Expand Up @@ -192,6 +192,12 @@
<version>0.5.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>pipeline-build-step</artifactId>
<version>2.11-20191211.174233-1</version> <!-- TODO https://github.com/jenkinsci/pipeline-build-step-plugin/pull/39 -->
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>pipeline-input-step</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ public Object readResolve() {

@Override public void onFailure(StepContext context, Throwable t) {
try {
if (!options.isCatchInterruptions() && t instanceof FlowInterruptedException) {
if (!options.isCatchInterruptions() && t instanceof FlowInterruptedException && ((FlowInterruptedException)t).isActualInterruption()) {
context.onFailure(t);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void onSuccess(StepContext context, Object result) {
@Override
public void onFailure(StepContext context, Throwable t) {
try {
if (t instanceof FlowInterruptedException) {
if (t instanceof FlowInterruptedException && ((FlowInterruptedException)t).isActualInterruption()) {
context.onFailure(t);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,20 @@ public class CatchErrorStepTest {
assertCatchError(r, b, Result.ABORTED, null, false);
}

@Issue("JENKINS-60354")
@Test public void catchesDownstreamBuildFailureEvenWhenNotCatchingInterruptions() throws Exception {
WorkflowJob ds = r.createProject(WorkflowJob.class);
ds.setDefinition(new CpsFlowDefinition("error 'oops!'", true));
WorkflowJob us = r.createProject(WorkflowJob.class);
us.setDefinition(new CpsFlowDefinition(
"int count = 1\n" +
"catchError(message: 'caught error', catchInterruptions: false) {\n" +
" build(job: '"+ds.getName()+"')\n" +
"}\n", true));
WorkflowRun b = r.assertBuildStatus(Result.FAILURE, us.scheduleBuild2(0));
assertCatchError(r, b, Result.FAILURE, Result.FAILURE, true);
}

public static void assertCatchError(JenkinsRule r, WorkflowRun run, Result buildResult, Result warningActionResult, boolean expectingCatch) throws Exception {
r.waitForCompletion(run);
r.assertBuildStatus(buildResult, run);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,22 @@ public void stackTraceOnError() throws Exception {
r.assertLogContains("Try #2", run);
r.assertLogContains("Done!", run);
}

@Issue("JENKINS-60354")
@Test
public void downstreamBuildFailureShouldRetry() throws Exception {
WorkflowJob ds = r.createProject(WorkflowJob.class);
ds.setDefinition(new CpsFlowDefinition("error 'oops!'", true));
WorkflowJob us = r.createProject(WorkflowJob.class);
us.setDefinition(new CpsFlowDefinition(
"int count = 1\n" +
"retry(3) {\n" +
" echo(/trying ${count++}/)\n" +
" build(job: '"+ds.getName()+"')\n" +
"}\n", true));
WorkflowRun b = r.assertBuildStatus(Result.FAILURE, us.scheduleBuild2(0));
r.assertLogContains("trying 1", b);
r.assertLogContains("trying 2", b);
r.assertLogContains("trying 3", b);
}
}