From 4279756a39ecf08ccb00786e410f955b6530abf6 Mon Sep 17 00:00:00 2001 From: Jesse Glick Date: Fri, 7 Apr 2023 16:56:23 -0400 Subject: [PATCH] =?UTF-8?q?Activate=20`KubernetesAgentErrorCondition`=20wh?= =?UTF-8?q?en=20`podTemplate=20{node=20{=E2=80=A6}}`=20fails=20to=20connec?= =?UTF-8?q?t?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pipeline/KubernetesAgentErrorCondition.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/KubernetesAgentErrorCondition.java b/src/main/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/KubernetesAgentErrorCondition.java index 61e7dc6022..20e4b36968 100644 --- a/src/main/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/KubernetesAgentErrorCondition.java +++ b/src/main/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/KubernetesAgentErrorCondition.java @@ -36,6 +36,7 @@ import org.jenkinsci.plugins.workflow.flow.FlowExecution; import org.jenkinsci.plugins.workflow.graph.BlockEndNode; import org.jenkinsci.plugins.workflow.graph.FlowNode; +import org.jenkinsci.plugins.workflow.graph.StepNode; import org.jenkinsci.plugins.workflow.graphanalysis.LinearBlockHoppingScanner; import org.jenkinsci.plugins.workflow.steps.StepContext; import org.jenkinsci.plugins.workflow.support.steps.AgentErrorCondition; @@ -91,6 +92,7 @@ public boolean test(Throwable t, StepContext context) throws IOException, Interr LOGGER.fine(() -> "Found origin " + origin + " " + origin.getDisplayFunctionName()); LinearBlockHoppingScanner scanner = new LinearBlockHoppingScanner(); scanner.setup(origin); + boolean foundPodTemplate = false; for (FlowNode callStack : scanner) { WorkspaceAction ws = callStack.getPersistentAction(WorkspaceAction.class); if (ws != null) { @@ -121,9 +123,15 @@ public boolean test(Throwable t, StepContext context) throws IOException, Interr LOGGER.fine(() -> "active on " + node + " (termination reasons: " + terminationReasons + ")"); return true; } + foundPodTemplate |= callStack instanceof StepNode && ((StepNode) callStack).getDescriptor() instanceof PodTemplateStep.DescriptorImpl; } if (!handleNonKubernetes) { - listener.getLogger().println("Could not find a node block associated with " + origin.getDisplayFunctionName() + " (source of error)"); + if (foundPodTemplate) { + listener.getLogger().println("Could not find a node block associated with " + origin.getDisplayFunctionName() + " (source of error) but inside podTemplate"); + return true; + } else { + listener.getLogger().println("Could not find a node block associated with " + origin.getDisplayFunctionName() + " (source of error)"); + } } return handleNonKubernetes; }