apache/dolphinscheduler · error · TaskException
Parse yaml-like commands and args failed
Error message
Parse yaml-like commands and args failed
What it means
K8sTaskExecutor.buildK8sJob() uses SnakeYAML to parse the task's 'command' and 'args' strings (expected to be YAML-like lists) into Java objects. If yaml.load() throws on malformed input, it wraps the exception in TaskException("Parse yaml-like commands and args failed"). The K8s Job spec cannot be built without these parsed values.
Source
Thrown at dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/k8s/impl/K8sTaskExecutor.java:151
EnvVar envVar = new EnvVar(param, paramValue, null);
envVars.add(envVar);
}
}
String commandString = k8STaskMainParameters.getCommand();
String argsString = k8STaskMainParameters.getArgs();
List<String> commands = new ArrayList<>();
List<String> args = new ArrayList<>();
try {
if (!StringUtils.isEmpty(commandString)) {
commands = yaml.load(commandString.trim());
}
if (!StringUtils.isEmpty(argsString)) {
args = yaml.load(argsString.trim());
}
} catch (Exception e) {
throw new TaskException("Parse yaml-like commands and args failed", e);
}
NodeSelectorTerm nodeSelectorTerm = new NodeSelectorTerm();
nodeSelectorTerm.setMatchExpressions(k8STaskMainParameters.getNodeSelectorRequirements());
Affinity affinity = k8STaskMainParameters.getNodeSelectorRequirements().size() == 0 ? null
: new AffinityBuilder()
.withNewNodeAffinity()
.withNewRequiredDuringSchedulingIgnoredDuringExecution()
.addNewNodeSelectorTermLike(nodeSelectorTerm)
.endNodeSelectorTerm()
.endRequiredDuringSchedulingIgnoredDuringExecution()
.endNodeAffinity().build();
job = new JobBuilder()
.withApiVersion(API_VERSION)
.withNewMetadata()
.withName(k8sJobName)View on GitHub (pinned to 02eac45a1b)
Solutions
- Rewrite the command/args fields as valid YAML list syntax, e.g. ["sh", "-c", "your command"].
- Validate the YAML locally (paste into a YAML parser) before saving the task definition.
- Replace tab indentation with spaces; quote values containing ':', '{', '}', '#', or leading special characters.
- Confirm the parsed result is a List (the code expects list-like output), not a scalar or map.
Example fix
// before (task params) command: echo hello && date // after command: ["sh", "-c", "echo hello && date"]
Defensive patterns
Strategy: validation
Validate before calling
try (Yaml yaml = new Yaml()) {
Object parsed = yaml.load(commandString == null ? "" : commandString.trim());
if (!(parsed instanceof List)) {
throw new IllegalArgumentException("command must be a YAML list, got: " + (parsed == null ? "null" : parsed.getClass().getSimpleName()));
}
} catch (Exception e) {
throw new IllegalArgumentException("Invalid YAML in command/args: " + e.getMessage(), e);
} Type guard
boolean isValidYamlList(String s) {
if (StringUtils.isEmpty(s)) return true; // treated as empty elsewhere
try {
return new Yaml().load(s.trim()) instanceof List;
} catch (Exception e) {
return false;
}
} Try / catch
try {
Object commands = yaml.load(commandString.trim());
} catch (Exception e) {
log.error("Invalid command/args YAML: {}", commandString, e);
throw new IllegalArgumentException("Fix command/args to YAML list form, e.g. [\"sh\",\"-c\",\"...\"]");
} Prevention
- Author command/args as YAML lists: ["sh", "-c", "your command"].
- Never use tabs; use spaces for any YAML indentation.
- Quote values containing YAML special characters (: { } # *).
- Test-parse the strings in a YAML linter before saving the task.
When it happens
Trigger: Calling submitJob2k8s/buildK8sJob when the K8sParameters' commandString or argsString is not valid YAML, e.g. plain text not formatted as a YAML list, tabs for indentation, unquoted special characters ('{', ':', '#'), or content that parses to a non-list type.
Common situations: Users typing shell-style commands (e.g. `echo hello` or comma-separated values) instead of YAML list syntax like `["sh","-c","echo hello"]`; hidden tab characters; strings starting with '{' or '*' that YAML treats specially.
Related errors
- namespace %s does not exist in k8s cluster, please create na
- fail to get k8s ApiClient:%s
- K8S_NAMESPACE_EXIST
- CLUSTER_NOT_EXISTS
- K8S_CLIENT_OPS_ERROR
AI-assisted analysis of apache/dolphinscheduler@02eac45a1b (2026-09-06).
Data as JSON: /api/errors/d9b604b275d19ce4.
Report an issue: GitHub.