{"record":{"id":"69539db4f63f79cb","repo":"hashicorp/nomad","slug":"no-lifecycle-hook-provided","errorCode":null,"errorMessage":"no lifecycle hook provided","messagePattern":"no lifecycle hook provided","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nomad/structs/structs.go","lineNumber":6187,"sourceCode":"\tif d == nil {\n\t\treturn nil\n\t}\n\tnd := new(TaskLifecycleConfig)\n\t*nd = *d\n\treturn nd\n}\n\nfunc (d *TaskLifecycleConfig) Validate() error {\n\tif d == nil {\n\t\treturn nil\n\t}\n\n\tswitch d.Hook {\n\tcase TaskLifecycleHookPrestart:\n\tcase TaskLifecycleHookPoststart:\n\tcase TaskLifecycleHookPoststop:\n\tcase \"\":\n\t\treturn fmt.Errorf(\"no lifecycle hook provided\")\n\tdefault:\n\t\treturn fmt.Errorf(\"invalid hook: %v\", d.Hook)\n\t}\n\n\treturn nil\n}\n\nvar (\n\t// These default restart policies needs to be in sync with\n\t// Canonicalize in api/tasks.go\n\n\tDefaultServiceJobRestartPolicy = RestartPolicy{\n\t\tDelay:           15 * time.Second,\n\t\tAttempts:        2,\n\t\tInterval:        30 * time.Minute,\n\t\tMode:            RestartPolicyModeFail,\n\t\tRenderTemplates: false,\n\t}","sourceCodeStart":6169,"sourceCodeEnd":6205,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/nomad/structs/structs.go#L6169-L6205","documentation":"TaskLifecycleConfig.Validate() requires the `hook` field to be one of prestart, poststart, or poststop. An empty `hook` value yields this error. It indicates the lifecycle block was provided but the hook name was omitted.","triggerScenarios":"Submitting a job with a `lifecycle { }` block attached to a task where `hook = \"\"` or the key is omitted/empty in HCL/JSON.","commonSituations":"Templated job files where the hook value is interpolated to an empty string; forgetting the `hook` key entirely; YAML/JSON job specs generated by tooling that writes an empty field.","solutions":["Set `hook` to one of `prestart`, `poststart`, or `poststop` in the task's lifecycle block.","If the task is not meant to be a lifecycle task, remove the lifecycle block entirely.","Fix the template/variable source producing an empty hook value."],"exampleFix":"// before\nlifecycle {\n  hook = \"\"\n}\n// after\nlifecycle {\n  hook = \"prestart\"\n}","handlingStrategy":"validation","validationCode":"validHooks := map[string]bool{\"prestart\": true, \"poststart\": true, \"poststop\": true}\nif lifecycle != nil && !validHooks[lifecycle.Hook] {\n\treturn fmt.Errorf(\"lifecycle.hook must be one of prestart, poststart, poststop\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use typed constants/enums for hook names instead of raw strings in generated job specs.","Never interpolate lifecycle.hook from an unset variable without a default.","Validate job files with `nomad job validate` in CI."],"tags":["nomad","job-spec","lifecycle","validation"],"backgroundTag":"missing-required-argument","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"}