hashicorp/packer · error
Either a script file or inline script must be specified.
Error message
Either a script file or inline script must be specified.
What it means
Windows-shell provisioner equivalent of error 6: Prepare() requires either a script file or inline commands, and the config provided neither. With an empty scripts list and nil inline there is nothing to execute on the Windows guest, so validation fails.
Source
Thrown at provisioner/windows-shell/provisioner.go:114
}
if p.config.Vars == nil {
p.config.Vars = make([]string, 0)
}
var errs error
if p.config.Script != "" && len(p.config.Scripts) > 0 {
errs = packersdk.MultiErrorAppend(errs,
errors.New("Only one of script or scripts can be specified."))
}
if p.config.Script != "" {
p.config.Scripts = []string{p.config.Script}
}
if len(p.config.Scripts) == 0 && p.config.Inline == nil {
errs = packersdk.MultiErrorAppend(errs,
errors.New("Either a script file or inline script must be specified."))
} else if len(p.config.Scripts) > 0 && p.config.Inline != nil {
errs = packersdk.MultiErrorAppend(errs,
errors.New("Only a script file or an inline script can be specified, not both."))
}
for _, path := range p.config.Scripts {
if _, err := os.Stat(path); err != nil {
errs = packersdk.MultiErrorAppend(errs,
fmt.Errorf("Bad script '%s': %s", path, err))
}
}
// Do a check for bad environment variables, such as '=foo', 'foobar'
for _, kv := range p.config.Vars {
vs := strings.SplitN(kv, "=", 2)
if len(vs) != 2 || vs[0] == "" {
errs = packersdk.MultiErrorAppend(errs,
fmt.Errorf("Environment variable not in format 'key=value': %s", kv))View on GitHub (pinned to eb36e3c3e4)
Solutions
- Add `inline = ["echo hello"]` for inline commands.
- Add `scripts = ["./setup.ps1"]` (or `script`) pointing at a .ps1/.bat/.cmd file.
- Remove the windows-shell block if it is not needed.
Example fix
// before
provisioner "windows-shell" {}
// after
provisioner "windows-shell" {
scripts = ["./setup.ps1"]
} Defensive patterns
Strategy: validation
Validate before calling
if len(cfg.Scripts) == 0 && cfg.Inline == nil {
return fmt.Errorf("windows-shell config: must set scripts, script, or inline")
} Prevention
- Never commit empty windows-shell blocks; remove or fill scaffolding.
- Give template variables used as `script` non-empty defaults and validate them.
- Run `packer validate` on templates in CI to catch missing command sources.
- Call Prepare() in unit tests with the final resolved config, not just the raw template.
When it happens
Trigger: Prepare() on provisioner/windows-shell is called with len(p.config.Scripts) == 0 and p.config.Inline == nil — an empty windows-shell block, or a `script` value that resolved to an empty string via template variables.
Common situations: Empty windows-shell block scaffold left in the template; an HCL variable defaulting to "" used as `script`; users specifying only elevated/env options and forgetting the command source.
Understand the failure class
Background: "X is required", "must be set", "cannot be empty": the missing-required-config error family, from Vertex AI project/location to WeChat keys — this error's family across 18 libraries.
Related errors
- Only one of script or scripts can be specified.
- source must be specified when auto_generate is not enabled
- Only one of script or scripts can be specified.
- Must supply an 'elevated_user' if 'elevated_password' provid
- Either a script file or inline script must be specified.
AI-assisted analysis of hashicorp/packer@eb36e3c3e4 (2026-09-05).
Data as JSON: /api/errors/180b8d919a7becff.
Report an issue: GitHub.