diff --git a/src/main/java/org/csanchez/jenkins/plugins/kubernetes/PodTemplateUtils.java b/src/main/java/org/csanchez/jenkins/plugins/kubernetes/PodTemplateUtils.java index a94472fc62..39d802c6bc 100644 --- a/src/main/java/org/csanchez/jenkins/plugins/kubernetes/PodTemplateUtils.java +++ b/src/main/java/org/csanchez/jenkins/plugins/kubernetes/PodTemplateUtils.java @@ -203,8 +203,12 @@ public static Container combine(@CheckForNull Container parent, @NonNull Contain String workingDir = isNullOrEmpty(template.getWorkingDir()) ? (isNullOrEmpty(parent.getWorkingDir()) ? DEFAULT_WORKING_DIR : parent.getWorkingDir()) : template.getWorkingDir(); - List command = template.getCommand() == null ? parent.getCommand() : template.getCommand(); - List args = template.getArgs() == null ? parent.getArgs() : template.getArgs(); + List command = + template.getCommand() == null || template.getCommand().isEmpty() + ? parent.getCommand() + : template.getCommand(); + List args = + template.getArgs() == null || template.getArgs().isEmpty() ? parent.getArgs() : template.getArgs(); Boolean tty = template.getTty() != null ? template.getTty() : parent.getTty(); Map requests = combineResources(parent, template, ResourceRequirements::getRequests); Map limits = combineResources(parent, template, ResourceRequirements::getLimits); diff --git a/src/test/java/org/csanchez/jenkins/plugins/kubernetes/PodTemplateUtilsTest.java b/src/test/java/org/csanchez/jenkins/plugins/kubernetes/PodTemplateUtilsTest.java index eee3c262b1..7d7a6fc7b5 100644 --- a/src/test/java/org/csanchez/jenkins/plugins/kubernetes/PodTemplateUtilsTest.java +++ b/src/test/java/org/csanchez/jenkins/plugins/kubernetes/PodTemplateUtilsTest.java @@ -937,4 +937,16 @@ private static void checkParsed(Pod pod) { .get(0) .getMode()); } + + @Test + @Issue("JENKINS-72886") + public void shouldIgnoreContainerEmptyArgs() { + Container parent = new Container(); + parent.setArgs(List.of("arg1", "arg2")); + parent.setCommand(List.of("parent command")); + Container child = new Container(); + Container result = combine(parent, child); + assertEquals(List.of("arg1", "arg2"), result.getArgs()); + assertEquals(List.of("parent command"), result.getCommand()); + } }