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

  1. Add `inline = ["echo hello"]` for inline commands.
  2. Add `scripts = ["./setup.ps1"]` (or `script`) pointing at a .ps1/.bat/.cmd file.
  3. 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

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


AI-assisted analysis of hashicorp/packer@eb36e3c3e4 (2026-09-05). Data as JSON: /api/errors/180b8d919a7becff. Report an issue: GitHub.