{"record":{"id":"dfdc4a6917cd64d3","repo":"hashicorp/packer","slug":"either-a-script-file-or-inline-script-must-be-spec-dfdc4a","errorCode":null,"errorMessage":"Either a script file or inline script must be specified.","messagePattern":"Either a script file or inline script must be specified\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"provisioner/shell/provisioner.go","lineNumber":161,"sourceCode":"\t}\n\n\tif p.config.Vars == nil {\n\t\tp.config.Vars = make([]string, 0)\n\t}\n\n\tvar errs *packersdk.MultiError\n\tif p.config.Script != \"\" && len(p.config.Scripts) > 0 {\n\t\terrs = packersdk.MultiErrorAppend(errs,\n\t\t\terrors.New(\"Only one of script or scripts can be specified.\"))\n\t}\n\n\tif p.config.Script != \"\" {\n\t\tp.config.Scripts = []string{p.config.Script}\n\t}\n\n\tif len(p.config.Scripts) == 0 && p.config.Inline == nil {\n\t\terrs = packersdk.MultiErrorAppend(errs,\n\t\t\terrors.New(\"Either a script file or inline script must be specified.\"))\n\t} else if len(p.config.Scripts) > 0 && p.config.Inline != nil {\n\t\terrs = packersdk.MultiErrorAppend(errs,\n\t\t\terrors.New(\"Only a script file or an inline script can be specified, not both.\"))\n\t}\n\n\tfor _, path := range p.config.Scripts {\n\t\tif _, err := os.Stat(path); err != nil {\n\t\t\terrs = packersdk.MultiErrorAppend(errs,\n\t\t\t\tfmt.Errorf(\"Bad script '%s': %s\", path, err))\n\t\t}\n\t}\n\n\t// Do a check for bad environment variables, such as '=foo', 'foobar'\n\tfor _, kv := range p.config.Vars {\n\t\tvs := strings.SplitN(kv, \"=\", 2)\n\t\tif len(vs) != 2 || vs[0] == \"\" {\n\t\t\terrs = packersdk.MultiErrorAppend(errs,\n\t\t\t\tfmt.Errorf(\"Environment variable not in format 'key=value': %s\", kv))","sourceCodeStart":143,"sourceCodeEnd":179,"githubUrl":"https://github.com/hashicorp/packer/blob/eb36e3c3e48a036f3e8cc94087636ee72e1303c9/provisioner/shell/provisioner.go#L143-L179","documentation":"Thrown by the shell provisioner's Prepare() when neither a script file nor inline commands were provided. The provisioner needs something to execute on the machine; with an empty `scripts` list and a nil `inline` field there is no work to do, so validation fails early with this error.","triggerScenarios":"Prepare() is called with len(p.config.Scripts) == 0 and p.config.Inline == nil — i.e. the provisioner block contains neither `script`/`scripts` nor `inline`. Also occurs when a configured `script` path is empty or the whole block was left without execution content.","commonSituations":"Empty shell provisioner block left as scaffolding (`provisioner \"shell\" {}`); template variable interpolation resolving to an empty string so `script` becomes \"\"; users setting only env_vars/useful keys but forgetting to specify what to run.","solutions":["Add `inline = [\"echo hello\"]` for ad-hoc commands.","Add `scripts = [\"./myscript.sh\"]` (or `script = \"./myscript.sh\"`) to point at a script file.","If the block is unused scaffolding, remove the shell provisioner block entirely."],"exampleFix":"// before\nprovisioner \"shell\" {}\n// after\nprovisioner \"shell\" {\n  inline = [\"echo hello\"]\n}","handlingStrategy":"validation","validationCode":"if len(cfg.Scripts) == 0 && cfg.Inline == nil {\n    return fmt.Errorf(\"provisioner config: must set scripts, script, or inline\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pair a shell provisioner block with at least one command source.","Check that template variables feeding `script` have non-empty defaults.","Treat an empty provisioner block as a template error and remove scaffolding.","Add a unit test calling Prepare() with your real config to catch it in CI."],"tags":["packer","provisioner","config-validation","shell"],"backgroundTag":"missing-required-config","analyzedSha":"eb36e3c3e48a036f3e8cc94087636ee72e1303c9","analyzedAt":"2026-09-05T13:20:43.127Z","contentChangedAt":"2026-09-05T13:20:43.127Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}