{"record":{"id":"7c17394697310764","repo":"hashicorp/nomad","slug":"lifecycle-validation-failed-v","errorCode":null,"errorMessage":"Lifecycle validation failed: %v","messagePattern":"Lifecycle validation failed: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nomad/structs/structs.go","lineNumber":8373,"sourceCode":"\t\tif handled, seen := actions[action.Name]; seen && !handled {\n\t\t\tmErr.Errors = append(mErr.Errors, fmt.Errorf(\"Action %s defined multiple times\", action.Name))\n\t\t\tactions[action.Name] = true\n\t\t\tcontinue\n\t\t}\n\t\tactions[action.Name] = false\n\t}\n\n\t// Validate the dispatch payload block if there\n\tif t.DispatchPayload != nil {\n\t\tif err := t.DispatchPayload.Validate(); err != nil {\n\t\t\tmErr.Errors = append(mErr.Errors, fmt.Errorf(\"Dispatch Payload validation failed: %v\", err))\n\t\t}\n\t}\n\n\t// Validate the Lifecycle block if there\n\tif t.Lifecycle != nil {\n\t\tif err := t.Lifecycle.Validate(); err != nil {\n\t\t\tmErr.Errors = append(mErr.Errors, fmt.Errorf(\"Lifecycle validation failed: %v\", err))\n\t\t}\n\n\t}\n\n\t// Validation for TaskKind field which is used for Consul Connect integration\n\tif t.Kind.IsConnectProxy() {\n\t\t// This task is a Connect proxy so it should not have service blocks\n\t\tif len(t.Services) > 0 {\n\t\t\tmErr.Errors = append(mErr.Errors, fmt.Errorf(\"Connect proxy task must not have a service block\"))\n\t\t}\n\t\tif t.Leader {\n\t\t\tmErr.Errors = append(mErr.Errors, fmt.Errorf(\"Connect proxy task must not have leader set\"))\n\t\t}\n\n\t\t// Ensure the proxy task has a corresponding service entry\n\t\tserviceErr := ValidateConnectProxyService(t.Kind.Value(), tg.Services)\n\t\tif serviceErr != nil {\n\t\t\tmErr.Errors = append(mErr.Errors, serviceErr)","sourceCodeStart":8355,"sourceCodeEnd":8391,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/nomad/structs/structs.go#L8355-L8391","documentation":"Task.Validate wraps Lifecycle.Validate failures as \"Lifecycle validation failed: %v\". Lifecycle blocks mark tasks as prestart/poststart/sidecar hooks, and validation rejects invalid hook names or illegal lifecycle configurations (e.g. on a system job).","triggerScenarios":"A task's `lifecycle` block specifies an invalid `hook` value or a `sidecar`/hook combination that fails validation, e.g. lifecycle on unsupported job types.","commonSituations":"Misspelling hook=\"PRESTART\" casing; adding sidecar tasks to system jobs; upgrading jobs written for older Nomad lifecycle semantics.","solutions":["Read the wrapped inner error to see which lifecycle field is invalid","Use only supported hook values: PRESTART, POSTSTART, POSTSTOP","Remove lifecycle from tasks where it is unsupported (e.g. system scheduler jobs)"],"exampleFix":"// before\nlifecycle {\n  hook = \"prestart-after\"\n}\n// after\nlifecycle {\n  hook = \"prestart\"\n}","handlingStrategy":"validation","validationCode":"if task.Lifecycle != nil {\n    if err := task.Lifecycle.Validate(); err != nil {\n        return fmt.Errorf(\"lifecycle: %w\", err)\n    }\n}","typeGuard":"var validHooks = map[string]bool{\"PRESTART\": true, \"POSTSTART\": true, \"POSTSTOP\": true}\nfunc hookValid(h string) bool { return validHooks[h] }","tryCatchPattern":"if err := job.Validate(); err != nil {\n    if strings.Contains(err.Error(), \"Lifecycle validation failed\") { /* fix lifecycle block */ }\n}","preventionTips":["Use only documented hook constants (PRESTART/POSTSTART/POSTSTOP)","Avoid lifecycle on system jobs","Re-validate job specs when upgrading Nomad"],"tags":["nomad","job-validation","lifecycle"],"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"}