{"record":{"id":"1db81dc7ac920607","repo":"hashicorp/packer","slug":"failed-cleaning-up-prior-artifact-s-pp-is-s","errorCode":null,"errorMessage":"Failed cleaning up prior artifact: %s; pp is %s","messagePattern":"Failed cleaning up prior artifact: (.+?); pp is (.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packer/build.go","lineNumber":447,"sourceCode":"\t\t\t\t// This is the first post-processor. We handle deleting\n\t\t\t\t// previous artifacts a bit different because multiple\n\t\t\t\t// post-processors may be using the original and need it.\n\t\t\t\tif !keepOriginalArtifact && keep {\n\t\t\t\t\tlog.Printf(\n\t\t\t\t\t\t\"Flagging to keep original artifact from post-processor '%s'\",\n\t\t\t\t\t\tcorePP.PType)\n\t\t\t\t\tkeepOriginalArtifact = true\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// We have a prior artifact. If we want to keep it, we append\n\t\t\t\t// it to the results list. Otherwise, we destroy it.\n\t\t\t\tif keep {\n\t\t\t\t\tartifacts = append(artifacts, priorArtifact)\n\t\t\t\t} else {\n\t\t\t\t\tlog.Printf(\"Deleting prior artifact from post-processor '%s'\", corePP.PType)\n\t\t\t\t\tif err := priorArtifact.Destroy(); err != nil {\n\t\t\t\t\t\tlog.Printf(\"Error is %#v\", err)\n\t\t\t\t\t\terrors = append(errors, fmt.Errorf(\"Failed cleaning up prior artifact: %s; pp is %s\", err, corePP.PType))\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tpriorArtifact = artifact\n\t\t}\n\n\t\t// Add on the last artifact to the results\n\t\tif priorArtifact != nil {\n\t\t\tartifacts = append(artifacts, priorArtifact)\n\t\t}\n\t}\n\n\tif keepOriginalArtifact {\n\t\tartifacts = append(artifacts, nil)\n\t\tcopy(artifacts[1:], artifacts)\n\t\tartifacts[0] = builderArtifact\n\t} else {","sourceCodeStart":429,"sourceCodeEnd":465,"githubUrl":"https://github.com/hashicorp/packer/blob/eb36e3c3e48a036f3e8cc94087636ee72e1303c9/packer/build.go#L429-L465","documentation":"After a post-processor produces an artifact and the keep/discard decision says not to keep it, Run calls priorArtifact.Destroy() to clean it up. If Destroy fails, Run records \"Failed cleaning up prior artifact: %s; pp is %s\" — the first %s is the destroy error and the second is the post-processor type whose artifact could not be deleted. The build's error list accumulates this but the chain continues.","triggerScenarios":"A post-processor artifact marked keep=false whose Destroy() implementation errors — e.g. the remote file/vagrant box/AMI it references cannot be deleted (permissions, already deleted, cloud API error).","commonSituations":"Cloud credentials lacking delete permissions (can create but not destroy resources); artifact file already removed externally;Destroy called on an artifact whose backing resource was reaped by a TTL; plugin bugs leaving Destroy unimplemented properly.","solutions":["Check the destroy error text and the named post-processor type for the failing resource","Verify credentials/permissions include delete rights for the artifact's backing resource (bucket, AMI, box)","Manually delete the orphaned artifact, then fix keep/discard config (keep_input_artifact, except rules) to prevent recreation of unwanted artifacts","Re-run with PACKER_LOG=1 to see the Destroy error details logged via log.Printf(\"Error is %#v\")"],"exampleFix":"// before\npost-processors {\n  post-processor \"checksum\" { }  // discarded artifact cleanup failing\n}\n// after - keep artifacts intentionally so cleanup is skipped, delete manually\npost-processors {\n  post-processor \"checksum\" { keep_input_artifact = true }\n}","handlingStrategy":"try-catch","validationCode":"// Ensure credentials can delete resources before discarding artifacts:\n// e.g. for S3 artifacts, verify s3:DeleteObject; for AMIs, ec2:DeregisterImage.","typeGuard":null,"tryCatchPattern":"artifacts, err := build.Run(ctx, ui)\nif err != nil {\n    var multi *packersdk.MultiError\n    if errors.As(err, &multi) {\n        for _, e := range multi.Errors {\n            if s := e.Error(); strings.Contains(s, \"Failed cleaning up prior artifact\") {\n                log.Printf(\"manual cleanup needed (orphaned artifact): %v\", e)\n            }\n        }\n    }\n    return err\n}","preventionTips":["Grant delete/deregister permissions to the credentials used by post-processors","Set keep_input_artifact / keep rules deliberately so you know which artifacts get auto-destroyed","Monitor for orphaned artifacts after failed builds and clean them via cloud consoles/CLI","Run builds with a unique run-tag so stray artifacts are easy to identify and sweep"],"tags":["artifact","post-processor","cleanup","destroy"],"backgroundTag":"artifact-destroy-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"}