Skip to content

Commit

Permalink
Merge pull request #254 from jglick/retry-unconditionally-JENKINS-49707
Browse files Browse the repository at this point in the history
[JENKINS-49707] `retry` without conditions should handle node removal
  • Loading branch information
jglick authored Jul 22, 2022
2 parents 9af20dd + 6ce4237 commit 02b9244
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
6 changes: 4 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
</pluginRepositories>
<properties>
<changelist>999999-SNAPSHOT</changelist>
<jenkins.version>2.332.1</jenkins.version>
<jenkins.version>2.346.1</jenkins.version>
<useBeta>true</useBeta>
<gitHubRepo>jenkinsci/${project.artifactId}-plugin</gitHubRepo>
<hpi.compatibleSinceVersion>2.40</hpi.compatibleSinceVersion>
Expand All @@ -75,7 +75,7 @@
<dependencies>
<dependency>
<groupId>io.jenkins.tools.bom</groupId>
<artifactId>bom-2.332.x</artifactId>
<artifactId>bom-2.346.x</artifactId>
<version>1478.v81d3dc4f9a_43</version>
<scope>import</scope>
<type>pom</type>
Expand All @@ -86,6 +86,7 @@
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-step-api</artifactId>
<version>639.v6eca_cd8c04a_a_</version> <!-- TODO until in BOM -->
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
Expand All @@ -102,6 +103,7 @@
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-cps</artifactId>
<version>2759.v87459c4eea_ca_</version> <!-- TODO until in BOM -->
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,11 @@ public static final class QueueTaskCancelled extends CauseOfInterruption {
continue;
}
listener.getLogger().println("Agent " + node.getNodeName() + " was deleted; cancelling node body");
body.cancel(new RemovedNodeCause());
if (Util.isOverridden(BodyExecution.class, body.getClass(), "cancel", Throwable.class)) {
body.cancel(new FlowInterruptedException(Result.ABORTED, false, new RemovedNodeCause()));
} else { // TODO remove once https://github.com/jenkinsci/workflow-cps-plugin/pull/570 is widely deployed
body.cancel(new RemovedNodeCause());
}
}
}
}, ExecutorPickle.TIMEOUT_WAITING_FOR_NODE_MILLIS, TimeUnit.MILLISECONDS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,31 @@ public static final class HangStep extends Step {
});
}

@Test public void retryUnconditionally() throws Throwable {
sessions.then(r -> {
Slave s = inboundAgents.createAgent(r, "dumbo1");
s.setLabelString("dumb");
r.jenkins.updateNode(s);
WorkflowJob p = r.createProject(WorkflowJob.class, "p");
p.setDefinition(new CpsFlowDefinition(
"retry(2) {\n" +
" node('dumb') {\n" +
" if (isUnix()) {sh 'sleep 10'} else {bat 'echo + sleep && ping -n 10 localhost'}\n" +
" }\n" +
"}", true));
WorkflowRun b = p.scheduleBuild2(0).waitForStart();
r.waitForMessage("+ sleep", b);
inboundAgents.stop("dumbo1");
r.jenkins.removeNode(s);
r.waitForMessage("Retrying", b);
s = inboundAgents.createAgent(r, "dumbo2");
s.setLabelString("dumb");
r.jenkins.updateNode(s);
r.waitForMessage("Running on dumbo2 in ", b);
r.assertBuildStatusSuccess(r.waitForCompletion(b));
});
}

@Test public void overallBuildCancelIgnored() throws Throwable {
sessions.then(r -> {
r.createSlave(Label.get("remote"));
Expand Down

0 comments on commit 02b9244

Please sign in to comment.