{"record":{"id":"14708056dedc32c9","repo":"hashicorp/packer","slug":"only-a-script-file-or-an-inline-script-can-be-spec-147080","errorCode":null,"errorMessage":"Only a script file or an inline script can be specified, not both.","messagePattern":"Only a script file or an inline script can be specified, not both\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"provisioner/shell/provisioner.go","lineNumber":164,"sourceCode":"\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))\n\t\t}\n\t}\n","sourceCodeStart":146,"sourceCodeEnd":182,"githubUrl":"https://github.com/hashicorp/packer/blob/eb36e3c3e48a036f3e8cc94087636ee72e1303c9/provisioner/shell/provisioner.go#L146-L182","documentation":"Thrown by the shell provisioner's Prepare() when the config supplies both a script file and inline commands. The two sources of commands are mutually exclusive — the provisioner cannot order them sensibly — so validation fails with this error before the build starts.","triggerScenarios":"Prepare() is called with len(p.config.Scripts) > 0 (via `script` or `scripts`) and p.config.Inline != nil at the same time, e.g. a block with both `script = \"setup.sh\"` and `inline = [\"echo hi\"]`.","commonSituations":"Appending `inline` quick-fix commands to an existing script-based provisioner; copy-pasting blocks where one used scripts and the other used inline; generated/merged templates combining sections from multiple sources.","solutions":["Move the inline commands into a script file and reference it via `scripts`, keeping only one source.","Remove the `inline` field and keep the script file(s).","Split into two separate shell provisioner blocks: one with `scripts`, one with `inline` (they run in template order)."],"exampleFix":"// before\nprovisioner \"shell\" {\n  scripts = [\"./setup.sh\"]\n  inline  = [\"echo done\"]\n}\n// after\nprovisioner \"shell\" {\n  scripts = [\"./setup.sh\"]\n}\nprovisioner \"shell\" {\n  inline = [\"echo done\"]\n}","handlingStrategy":"validation","validationCode":"if len(cfg.Scripts) > 0 && cfg.Inline != nil {\n    return fmt.Errorf(\"provisioner config: use scripts or inline, not both\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Choose one execution style per block; split into two ordered provisioner blocks if you need both.","Lint templates for coexisting `inline` and `script(s)` keys.","When appending a quick command, add a new provisioner block instead of editing the script-based one."],"tags":["packer","provisioner","config-validation","shell"],"backgroundTag":"mutually-exclusive-config-options","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"}