Skip to content

Commit

Permalink
[JENKINS-72886] fix command & args are lost when combining contai…
Browse files Browse the repository at this point in the history
…ner templates (#1525)
  • Loading branch information
moleus committed Mar 19, 2024
1 parent 46e33be commit 1dd44f5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> command = template.getCommand() == null ? parent.getCommand() : template.getCommand();
List<String> args = template.getArgs() == null ? parent.getArgs() : template.getArgs();
List<String> command =
template.getCommand() == null || template.getCommand().isEmpty()
? parent.getCommand()
: template.getCommand();
List<String> args =
template.getArgs() == null || template.getArgs().isEmpty() ? parent.getArgs() : template.getArgs();
Boolean tty = template.getTty() != null ? template.getTty() : parent.getTty();
Map<String, Quantity> requests = combineResources(parent, template, ResourceRequirements::getRequests);
Map<String, Quantity> limits = combineResources(parent, template, ResourceRequirements::getLimits);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

0 comments on commit 1dd44f5

Please sign in to comment.