{"record":{"id":"e8698eb493194a10","repo":"hashicorp/packer","slug":"clean-up-script-q-failed-to-upload-s","errorCode":null,"errorMessage":"clean up script %q failed to upload: %s","messagePattern":"clean up script %q failed to upload: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"provisioner/powershell/provisioner.go","lineNumber":458,"sourceCode":"}\n\n// createRemoteCleanUpCommand will generated a powershell script that will remove remote files;\n// returning a command that can be executed remotely to do the cleanup.\nfunc (p *Provisioner) createRemoteCleanUpCommand(remoteFiles []string) (string, error) {\n\tif len(remoteFiles) == 0 {\n\t\treturn \"\", fmt.Errorf(\"no remoteFiles provided for cleanup\")\n\t}\n\n\tvar b strings.Builder\n\t// This script should self destruct.\n\tremotePath := p.config.remoteCleanUpScriptPath\n\tremoteFiles = append(remoteFiles, remotePath)\n\tfor _, filename := range remoteFiles {\n\t\tfmt.Fprintf(&b, \"if (Test-Path %[1]s) {Remove-Item %[1]s}\\n\", filename)\n\t}\n\n\tif err := p.communicator.Upload(remotePath, strings.NewReader(b.String()), nil); err != nil {\n\t\treturn \"\", fmt.Errorf(\"clean up script %q failed to upload: %s\", remotePath, err)\n\t}\n\n\tdata := p.generatedData\n\tdata[\"Path\"] = remotePath\n\tdata[\"Vars\"] = p.config.RemoteEnvVarPath\n\tp.config.ctx.Data = data\n\n\tp.config.ctx.Data = data\n\treturn interpolate.Render(p.config.ExecuteCommand, &p.config.ctx)\n}\n\n// Environment variables required within the remote environment are uploaded\n// within a PS script and then enabled by 'dot sourcing' the script\n// immediately prior to execution of the main command\nfunc (p *Provisioner) prepareEnvVars(elevated bool) (err error) {\n\t// Collate all required env vars into a plain string with required\n\t// formatting applied\n\tflattenedEnvVars := p.createFlattenedEnvVars(elevated)","sourceCodeStart":440,"sourceCodeEnd":476,"githubUrl":"https://github.com/hashicorp/packer/blob/eb36e3c3e48a036f3e8cc94087636ee72e1303c9/provisioner/powershell/provisioner.go#L440-L476","documentation":"After generating the self-destructing cleanup script, the provisioner uploads it to remoteCleanUpScriptPath via p.communicator.Upload. If that upload fails, the error wraps the remote path and the underlying cause. The build can proceed but stale files will remain on the guest (and this error is surfaced from provisioning).","triggerScenarios":"communicator.Upload fails while writing the cleanup script to remoteCleanUpScriptPath: connection drop, permission denied on the remote path, guest disk full, or SFTP/WinRM protocol error.","commonSituations":"Same conditions as any communicator upload failure: flaky guest network, read-only or nonexistent target directory, full guest disk, guest restarting mid-provision.","solutions":["Confirm the directory of remote_clean_up_script_path (default under the temp dir) exists and is writable on the guest.","Check guest connectivity/SSH or WinRM logs for the underlying transport error.","Free disk space on the guest if uploads are failing due to quota.","Retry the build if the cause was a transient network blip."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep guest connectivity stable during provisioning.","Ensure the cleanup script path's directory is writable.","Watch guest disk usage and antivirus interference on Windows.","Rerun the build after transient network errors and manually clean stale files."],"tags":["network","upload","powershell","cleanup"],"backgroundTag":"communicator-upload-failed","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"}