1919import hudson .Extension ;
2020import hudson .ExtensionList ;
2121import hudson .model .Node ;
22+ import hudson .model .TaskListener ;
2223import hudson .model .labels .LabelAtom ;
2324import java .io .IOException ;
2425import java .util .HashSet ;
3637import org .jenkinsci .plugins .workflow .graph .BlockEndNode ;
3738import org .jenkinsci .plugins .workflow .graph .FlowNode ;
3839import org .jenkinsci .plugins .workflow .graphanalysis .LinearBlockHoppingScanner ;
39- import org .jenkinsci .plugins .workflow .steps .FlowInterruptedException ;
4040import org .jenkinsci .plugins .workflow .steps .StepContext ;
4141import org .jenkinsci .plugins .workflow .support .steps .AgentErrorCondition ;
42- import org .jenkinsci .plugins .workflow .support .steps .ExecutorStepExecution ;
4342import org .kohsuke .stapler .DataBoundConstructor ;
4443import org .kohsuke .stapler .DataBoundSetter ;
4544
@@ -80,9 +79,12 @@ public boolean test(Throwable t, StepContext context) throws IOException, Interr
8079 LOGGER .fine (() -> "Not a recognized failure: " + t );
8180 return false ;
8281 }
82+ TaskListener listener = context .get (TaskListener .class );
8383 FlowNode _origin = ErrorAction .findOrigin (t , context .get (FlowExecution .class ));
8484 if (_origin == null ) {
85- LOGGER .fine (() -> "No recognized origin of error: " + t );
85+ if (!handleNonKubernetes ) {
86+ listener .getLogger ().println ("Unable to identify source of error (" + t + ") to see if this was associated with a Kubernetes agent" );
87+ }
8688 return handleNonKubernetes ;
8789 }
8890 FlowNode origin = _origin instanceof BlockEndNode ? ((BlockEndNode ) _origin ).getStartNode () : _origin ;
@@ -96,27 +98,33 @@ public boolean test(Throwable t, StepContext context) throws IOException, Interr
9698 Node n = Jenkins .get ().getNode (node );
9799 if (n != null ) {
98100 if (!(n instanceof KubernetesSlave )) {
99- LOGGER .fine (() -> node + " was not a K8s agent" );
101+ if (!handleNonKubernetes ) {
102+ listener .getLogger ().println (node + " was not a Kubernetes agent" );
103+ }
100104 return handleNonKubernetes ;
101105 }
102106 } else {
103107 // May have been removed already, but we can look up the labels to see what it was.
104108 Set <LabelAtom > labels = ws .getLabels ();
105109 if (labels .stream ().noneMatch (l -> Jenkins .get ().clouds .stream ().anyMatch (c -> c instanceof KubernetesCloud && ((KubernetesCloud ) c ).getTemplate (l ) != null ))) {
106- LOGGER .fine (() -> node + " was not a K8s agent judging by " + labels );
110+ if (!handleNonKubernetes ) {
111+ listener .getLogger ().println (node + " was not a Kubernetes agent judging by " + labels );
112+ }
107113 return handleNonKubernetes ;
108114 }
109115 }
110116 Set <String > terminationReasons = ExtensionList .lookupSingleton (Reaper .class ).terminationReasons (node );
111117 if (terminationReasons .stream ().anyMatch (r -> IGNORED_CONTAINER_TERMINATION_REASONS .contains (r ))) {
112- LOGGER . fine (() -> "ignored termination reason(s) for " + node + ": " + terminationReasons );
118+ listener . getLogger (). println ( "Ignored termination reason(s) for " + node + " for purposes of retry : " + terminationReasons );
113119 return false ;
114120 }
115121 LOGGER .fine (() -> "active on " + node + " (termination reasons: " + terminationReasons + ")" );
116122 return true ;
117123 }
118124 }
119- LOGGER .fine (() -> "found no WorkspaceAction starting from " + origin );
125+ if (!handleNonKubernetes ) {
126+ listener .getLogger ().println ("Could not find a node block associated with " + origin .getDisplayFunctionName () + " (source of error)" );
127+ }
120128 return handleNonKubernetes ;
121129 }
122130
0 commit comments