From 067e5efd01c2d3938d23ffeac3090ecad6d8342f Mon Sep 17 00:00:00 2001 From: Jesse Glick Date: Wed, 25 May 2022 11:50:49 -0400 Subject: [PATCH] Add form validation for `RetryStep.count` --- .../jenkinsci/plugins/workflow/steps/RetryStep.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/main/java/org/jenkinsci/plugins/workflow/steps/RetryStep.java b/src/main/java/org/jenkinsci/plugins/workflow/steps/RetryStep.java index 25033550..32533b8c 100644 --- a/src/main/java/org/jenkinsci/plugins/workflow/steps/RetryStep.java +++ b/src/main/java/org/jenkinsci/plugins/workflow/steps/RetryStep.java @@ -27,9 +27,11 @@ import edu.umd.cs.findbugs.annotations.NonNull; import hudson.Extension; import hudson.model.TaskListener; +import hudson.util.FormValidation; import java.util.Collections; import java.util.Set; import org.kohsuke.stapler.DataBoundConstructor; +import org.kohsuke.stapler.QueryParameter; /** * Executes the body up to N times. @@ -83,6 +85,16 @@ public Set> getRequiredContext() { return Collections.singleton(TaskListener.class); } + public FormValidation doCheckCount(@QueryParameter int count) { + if (count < 1) { + return FormValidation.error("Count must be positive."); + } else if (count == 1) { + return FormValidation.warning("Count of one means that the retry step has no effect. Use ≥2."); + } else { + return FormValidation.ok(); + } + } + } }