File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed
src/main/java/org/csanchez/jenkins/plugins/kubernetes Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -277,6 +277,26 @@ podTemplate(containers: […]) {
277277}
278278```
279279
280+ ### Retrying after infrastructure outages
281+
282+ You can use the ` retry ` step to automatically try the whole build stage again with a fresh pod in case of fatal infrastructure problems.
283+ (For example: cluster backup & restore; node pool used for agents drained and upgraded.)
284+
285+ ``` groovy
286+ podTemplate(…) {
287+ retry(count: 2, conditions: [kubernetesAgent(), nonresumable()]) {
288+ node(POD_LABEL) {
289+ sh 'your-build-process'
290+ }
291+ }
292+ }
293+ ```
294+
295+ will rerun the whole ` node ` block (using the same pod definition) in case the first attempt fails for a qualifying reason traceable to loss of the pod
296+ (_ not_ routine problems such as compilation errors or ` OutOfMemoryError ` ).
297+
298+ For Declarative Pipeline, just add the ` retries ` option, as shown below.
299+
280300# Configuration reference
281301## Pod template
282302
@@ -588,6 +608,7 @@ pipeline {
588608 - cat
589609 tty: true
590610 '''
611+ retries 2
591612 }
592613 }
593614 stages {
@@ -612,6 +633,7 @@ pipeline {
612633 agent {
613634 kubernetes {
614635 yamlFile 'KubernetesPod.yaml'
636+ retries 2
615637 }
616638 }
617639 stages {
Original file line number Diff line number Diff line change @@ -235,6 +235,8 @@ private static KubernetesCloud getKubernetesCloud(String cloudName) {
235235 Cloud cloud = Jenkins .get ().getCloud (cloudName );
236236 if (cloud instanceof KubernetesCloud ) {
237237 return (KubernetesCloud ) cloud ;
238+ } else if (cloud == null ) {
239+ throw new IllegalStateException ("No such cloud " + cloudName );
238240 } else {
239241 throw new IllegalStateException (KubernetesSlave .class .getName () + " can be launched only by instances of " + KubernetesCloud .class .getName () + ". Cloud is " + cloud .getClass ().getName ());
240242 }
You can’t perform that action at this time.
0 commit comments