{"record":{"id":"4b02800e00cdc15d","repo":"hashicorp/nomad","slug":"task-s-validation-failed-v","errorCode":null,"errorMessage":"Task %s validation failed: %v","messagePattern":"Task (.+?) validation failed: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nomad/structs/structs.go","lineNumber":7319,"sourceCode":"\t\tmErr = multierror.Append(mErr, outer)\n\t}\n\n\t// Validate group service script-checks\n\tif err := tg.validateScriptChecksInGroupServices(); err != nil {\n\t\touter := fmt.Errorf(\"Task group service check validation failed: %v\", err)\n\t\tmErr = multierror.Append(mErr, outer)\n\t}\n\n\t// Validate the scaling policy\n\tif err := tg.validateScalingPolicy(j); err != nil {\n\t\touter := fmt.Errorf(\"Task group scaling policy validation failed: %v\", err)\n\t\tmErr = multierror.Append(mErr, outer)\n\t}\n\n\t// Validate the tasks\n\tfor _, task := range tg.Tasks {\n\t\tif err := task.Validate(j.Type, tg); err != nil {\n\t\t\touter := fmt.Errorf(\"Task %s validation failed: %v\", task.Name, err)\n\t\t\tmErr = multierror.Append(mErr, outer)\n\t\t}\n\t}\n\n\treturn mErr.ErrorOrNil()\n}\n\nfunc (tg *TaskGroup) validateNetworks() error {\n\tvar mErr multierror.Error\n\tportLabels := make(map[string]string)\n\t// host_network -> static port tracking\n\tstaticPortsIndex := make(map[string]map[int]string)\n\tcniArgKeys := set.New[string](len(tg.Networks))\n\n\tfor _, net := range tg.Networks {\n\t\tfor _, port := range append(net.ReservedPorts, net.DynamicPorts...) {\n\t\t\tif other, ok := portLabels[port.Label]; ok {\n\t\t\t\tmErr.Errors = append(mErr.Errors, fmt.Errorf(\"Port label %s already in use by %s\", port.Label, other))","sourceCodeStart":7301,"sourceCodeEnd":7337,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/nomad/structs/structs.go#L7301-L7337","documentation":"Produced during job validation when `task.Validate(j.Type, tg)` fails for a task inside a task group. Nomad wraps the task's own validation error as 'Task %s validation failed: %v' and appends it to the group multierror. It means one task's config (driver, resources, artifacts, services, templates, etc.) is invalid for the job's type.","triggerScenarios":"Registering a job where a task has: an unknown/unavailable driver name, invalid resource stanza (negative CPU/memory, memory above limits), invalid service/check definitions, bad artifact sources, invalid template stanza, invalid log config, or a task field not permitted for the given job type.","commonSituations":"Typo in driver name (e.g. \"docker\" misspelled); referencing task group network port labels that don't exist; memory oversubscription fields on older Nomad versions; copy-pasted task stanzas carrying fields from another driver; template/consul misconfigurations caught at submit time.","solutions":["Read the wrapped '%v' detail to see which task stanza failed","Run `nomad job validate <file>` locally to catch the exact task error before submit","Fix the offending field in the named task (driver, resources, services, template, artifact...)","Ensure referenced port labels and group-level stanzas exist in the parent task group","Compare against a known-good example for the driver/version you target"],"exampleFix":"// before\ntask \"app\" {\n  driver = \"dockr\"\n  resources {\n    cpu    = -100\n    memory = 0\n  }\n}\n// after\ntask \"app\" {\n  driver = \"docker\"\n  resources {\n    cpu    = 500\n    memory = 256\n  }\n}","handlingStrategy":"validation","validationCode":"func validateTasks(j *api.Job) error {\n  var errs error\n  for _, tg := range j.TaskGroups {\n    for _, t := range tg.Tasks {\n      if t.Driver == \"\" { errs = multierror.Append(errs, fmt.Errorf(\"task %s: missing driver\", t.Name)) }\n      if r := t.Resources; r != nil {\n        if r.CPU < 0 || r.MemoryMB < 0 { errs = multierror.Append(errs, fmt.Errorf(\"task %s: negative resources\", t.Name)) }\n      }\n      // port label refs in services must exist in group network\n      labels := map[string]bool{}\n      for _, n := range tg.Networks { for _, p := range n.ReservedPorts { labels[p.Label] = true }; for _, p := range n.DynamicPorts { labels[p.Label] = true } }\n      for _, s := range t.Services { if s.PortLabel != \"\" && !labels[s.PortLabel] { errs = multierror.Append(errs, fmt.Errorf(\"task %s: unknown port label %q\", t.Name, s.PortLabel)) } }\n    }\n  }\n  return errs\n}","typeGuard":"func taskValid(t *api.Task) bool {\n  return t.Name != \"\" && t.Driver != \"\" && t.Resources != nil &&\n    t.Resources.CPU >= 0 && t.Resources.MemoryMB >= 0\n}","tryCatchPattern":null,"preventionTips":["Run `nomad job validate` on every spec before submit (CI gate)","Use schema-aware tooling (Terraform nomad_job, Packer templates) rather than raw string templating","Copy task stanzas from driver-specific official examples","Check port label references match group network definitions after refactors"],"tags":["nomad","job-validation","task","hcl"],"backgroundTag":"job-spec-validation-failed","analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}