{"record":{"id":"21f79bc1e31df82a","repo":"hashicorp/packer","slug":"no-remotefiles-provided-for-cleanup","errorCode":null,"errorMessage":"no remoteFiles provided for cleanup","messagePattern":"no remoteFiles provided for cleanup","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"provisioner/powershell/provisioner.go","lineNumber":446,"sourceCode":"\t\treturn cmd.RunWithUi(ctx, comm, ui)\n\t})\n\tif err != nil {\n\t\tlog.Printf(\"remote cleanup script failed to upload; skipping the removal of temporary files: %s; \", strings.Join(uploadedScripts, \",\"))\n\t}\n\n\tif p.config.PauseAfter != 0 {\n\t\tui.Say(fmt.Sprintf(\"Pausing %s after this provisioner...\", p.config.PauseAfter))\n\t\ttime.Sleep(p.config.PauseAfter)\n\t}\n\n\treturn nil\n}\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","sourceCodeStart":428,"sourceCodeEnd":464,"githubUrl":"https://github.com/hashicorp/packer/blob/eb36e3c3e48a036f3e8cc94087636ee72e1303c9/provisioner/powershell/provisioner.go#L428-L464","documentation":"createRemoteCleanUpCommand builds a PowerShell one-liner that deletes the uploaded remote files after execution. It refuses to generate that script when remoteFiles is empty, because there is nothing to clean up and uploading a cleanup script would itself leave a stray remote file. This is an internal invariant violation of the provisioner, not normally caused by user configuration.","triggerScenarios":"The provisioner calls createRemoteCleanUpCommand with an empty remoteFiles slice — i.e. no script/env-var remote files were recorded for deletion, which would indicate an internal bug in how the provisioner tracked uploaded files.","commonSituations":"Practically only seen during development/patching of the powershell provisioner itself, or when a modified code path skips registering uploaded files; end users should never trigger it via template configuration.","solutions":["If you hit this in a stock Packer build, report it as a bug with the full debug log (PACKER_LOG=1).","If you maintain a fork, ensure every uploaded remote file (script and env-var file) is appended to the remoteFiles list before cleanup is generated.","As a workaround, clean up leftover files manually on the guest; the error means nothing was deleted."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use stock Packer; if triggered, capture PACKER_LOG=1 output and file a bug.","In forks, always register every uploaded remote file in the cleanup list.","Manually remove leftover remote files after a failed cleanup."],"tags":["provisioner","powershell","internal-invariant","cleanup"],"backgroundTag":"empty-file-list-cleanup","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"}