Skip to content

Commit 1dd44f5

Browse files
authored
[JENKINS-72886] fix command & args are lost when combining container templates (#1525)
1 parent 46e33be commit 1dd44f5

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/main/java/org/csanchez/jenkins/plugins/kubernetes/PodTemplateUtils.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,12 @@ public static Container combine(@CheckForNull Container parent, @NonNull Contain
203203
String workingDir = isNullOrEmpty(template.getWorkingDir())
204204
? (isNullOrEmpty(parent.getWorkingDir()) ? DEFAULT_WORKING_DIR : parent.getWorkingDir())
205205
: template.getWorkingDir();
206-
List<String> command = template.getCommand() == null ? parent.getCommand() : template.getCommand();
207-
List<String> args = template.getArgs() == null ? parent.getArgs() : template.getArgs();
206+
List<String> command =
207+
template.getCommand() == null || template.getCommand().isEmpty()
208+
? parent.getCommand()
209+
: template.getCommand();
210+
List<String> args =
211+
template.getArgs() == null || template.getArgs().isEmpty() ? parent.getArgs() : template.getArgs();
208212
Boolean tty = template.getTty() != null ? template.getTty() : parent.getTty();
209213
Map<String, Quantity> requests = combineResources(parent, template, ResourceRequirements::getRequests);
210214
Map<String, Quantity> limits = combineResources(parent, template, ResourceRequirements::getLimits);

src/test/java/org/csanchez/jenkins/plugins/kubernetes/PodTemplateUtilsTest.java

+12
Original file line numberDiff line numberDiff line change
@@ -937,4 +937,16 @@ private static void checkParsed(Pod pod) {
937937
.get(0)
938938
.getMode());
939939
}
940+
941+
@Test
942+
@Issue("JENKINS-72886")
943+
public void shouldIgnoreContainerEmptyArgs() {
944+
Container parent = new Container();
945+
parent.setArgs(List.of("arg1", "arg2"));
946+
parent.setCommand(List.of("parent command"));
947+
Container child = new Container();
948+
Container result = combine(parent, child);
949+
assertEquals(List.of("arg1", "arg2"), result.getArgs());
950+
assertEquals(List.of("parent command"), result.getCommand());
951+
}
940952
}

0 commit comments

Comments
 (0)