hashicorp/packer · error
Error uploading ps script containing env vars: %s
Error message
Error uploading ps script containing env vars: %s
What it means
The PowerShell provisioner flattens the configured environment variables into a .ps1 file and uploads it to RemoteEnvVarPath inside a retry loop (StartRetryTimeout). This error wraps any failure from that communicator Upload. The env-vars script never landed on the guest, so command execution that depends on it will fail or run without those variables.
Source
Thrown at provisioner/powershell/provisioner.go:576
// Re-assemble vars using OS specific format pattern and flatten
for _, key := range keys {
flattened += fmt.Sprintf(format, key, envVars[key])
}
return
}
func (p *Provisioner) uploadEnvVars(flattenedEnvVars string) (err error) {
ctx := context.TODO()
// Upload all env vars to a powershell script on the target build file
// system. Do this in the context of a single retryable function so that
// we gracefully handle any errors created by transient conditions such as
// a system restart
envVarReader := strings.NewReader(flattenedEnvVars)
log.Printf("Uploading env vars to %s", p.config.RemoteEnvVarPath)
err = retry.Config{StartTimeout: p.config.StartRetryTimeout}.Run(ctx, func(context.Context) error {
if err := p.communicator.Upload(p.config.RemoteEnvVarPath, envVarReader, nil); err != nil {
return fmt.Errorf("Error uploading ps script containing env vars: %s", err)
}
return err
})
return
}
func (p *Provisioner) createCommandText() (command string, err error) {
// Return the interpolated command
if p.config.ElevatedUser == "" {
return p.createCommandTextNonPrivileged()
} else {
return p.createCommandTextPrivileged()
}
}
func (p *Provisioner) createCommandTextNonPrivileged() (command string, err error) {
// Prepare everything needed to enable the required env vars within the
// remote environmentView on GitHub (pinned to eb36e3c3e4)
Solutions
- Inspect the wrapped cause in the message (after the colon) to see the transport-level reason.
- Ensure the guest stays up and connected for the whole provision phase; disable guest auto-restart during builds.
- Verify the env var script path's directory is writable by the communicator user.
- Increase start_retry_timeout to ride out longer transient outages.
- Retry the build; transient conditions are explicitly expected to be handled by the retry loop.
Example fix
// before "start_retry_timeout": "5m" // after "start_retry_timeout": "10m"
Defensive patterns
Strategy: retry
Prevention
- Read the wrapped cause after the colon to identify the transport failure.
- Increase start_retry_timeout for guests prone to restarts.
- Keep env var script path in a writable directory.
- Stabilize guest network/SSH or WinRM service during builds.
When it happens
Trigger: communicator.Upload of the env-var .ps1 fails: transient SSH/WinRM disconnects across all retries, permission denied at RemoteEnvVarPath, guest disk full, or upload protocol errors.
Common situations: Guest reboots or loses network during provisioning; env_var_script_path's directory not writable; antivirus on Windows guests locking newly created files in temp; long builds where the session times out.
Related errors
- Error uploading script: %s
- clean up script %q failed to upload: %s
- Failed to upload sboms %s
- failed to upload Packer release zip: %s
- failed to upload Packer binary: %s
AI-assisted analysis of hashicorp/packer@eb36e3c3e4 (2026-09-05).
Data as JSON: /api/errors/47e9368717e75552.
Report an issue: GitHub.