Skip to content

Commit 85e0d7e

Browse files
authored
Merge pull request #1118 from mor120/terminate-on-create-container-error
2 parents 148c428 + b893977 commit 85e0d7e

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

src/main/java/org/csanchez/jenkins/plugins/kubernetes/pod/retention/Reaper.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,9 @@ public void onEvent(@NonNull Action action, @NonNull KubernetesSlave node, @NonN
240240
LOGGER.info(() -> ns + "/" + name + " Container " + c.getName() + " was just terminated, so removing the corresponding Jenkins agent");
241241
runListener.getLogger().printf("%s/%s Container %s was terminated (Exit Code: %d, Reason: %s)%n", ns, name, c.getName(), t.getExitCode(), t.getReason());
242242
});
243+
try (ACLContext _ = ACL.as(ACL.SYSTEM)) {
244+
PodUtils.cancelQueueItemFor(pod, "ContainerError");
245+
}
243246
logLastLinesThenTerminateNode(node, pod, runListener);
244247
}
245248
}

src/test/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/KubernetesDeclarativeAgentTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,13 @@ public void declarativeWithNonexistentDockerImage() throws Exception {
179179
r.assertLogContains("ERROR: Unable to pull Docker image", b);
180180
}
181181

182+
@Test
183+
public void declarativeWithCreateContainerError() throws Exception {
184+
assertNotNull(createJobThenScheduleRun());
185+
r.assertBuildStatus(Result.ABORTED, r.waitForCompletion(b));
186+
r.assertLogContains("was terminated", b);
187+
}
188+
182189
@Issue("JENKINS-61360")
183190
@Test
184191
public void declarativeShowRawYamlFalse() throws Exception {
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
pipeline {
2+
agent {
3+
kubernetes {
4+
yaml '''
5+
apiVersion: v1
6+
kind: Pod
7+
metadata:
8+
labels:
9+
some-label: some-label-value
10+
spec:
11+
containers:
12+
- name: busybox
13+
image: busybox
14+
tty: true
15+
command: ['sh', '-c', "thiscommandshouldcreateanerror;"]
16+
'''
17+
}
18+
}
19+
stages {
20+
stage('Run') {
21+
steps {
22+
container('busybox') {
23+
sh """
24+
will never run
25+
"""
26+
}
27+
}
28+
}
29+
}
30+
}

0 commit comments

Comments
 (0)