{"record":{"id":"68682fd2796f733a","repo":"GoogleContainerTools/skaffold","slug":"running-builder-post-hooks-w","errorCode":null,"errorMessage":"running builder post-hooks: %w","messagePattern":"running builder post-hooks: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/skaffold/runner/builder.go","lineNumber":107,"sourceCode":"\t\treturn err\n\t}\n\n\tif err := b.hooksRunner.RunPreHooks(ctx, out); err != nil {\n\t\treturn fmt.Errorf(\"running builder pre-hooks: %w\", err)\n\t}\n\n\treturn nil\n}\n\n// PostBuild executes any one-time teardown required after all builds on this builder are complete,\n// followed by any Build post-hooks set for the pipeline.\nfunc (b *pipelineBuilderWithHooks) PostBuild(ctx context.Context, out io.Writer) error {\n\tif err := b.PipelineBuilder.PostBuild(ctx, out); err != nil {\n\t\treturn err\n\t}\n\n\tif err := b.hooksRunner.RunPostHooks(ctx, out); err != nil {\n\t\treturn fmt.Errorf(\"running builder post-hooks: %w\", err)\n\t}\n\n\treturn nil\n}\n\nfunc withPipelineBuildHooks(pb build.PipelineBuilder, buildHooks latest.BuildHooks) build.PipelineBuilder {\n\treturn &pipelineBuilderWithHooks{\n\t\tPipelineBuilder: pb,\n\t\thooksRunner:     hooks.BuildRunner(buildHooks, hooks.BuildEnvOpts{}),\n\t}\n}\n","sourceCodeStart":89,"sourceCodeEnd":119,"githubUrl":"https://github.com/GoogleContainerTools/skaffold/blob/a1189de023efc32d4b8e11f395acc678aa555011/pkg/skaffold/runner/builder.go#L89-L119","documentation":"pipelineBuilderWithHooks.PostBuild runs the underlying builder's PostBuild, then executes build post-hooks. If any post-hook command fails, it is wrapped as \"running builder post-hooks: %w\". Post-hooks run after all builds are complete, so this signals teardown/cleanup hook failure.","triggerScenarios":"A `build.postHooks` command configured in skaffold.yaml exits non-zero after artifact builds finish.","commonSituations":"Cleanup or artifact-push scripts failing because a registry is unreachable, credentials are missing, or the cleanup command assumes files that were not produced.","solutions":["Inspect the wrapped error and run the failing post-hook command manually to reproduce","Fix the post-hook command/script in skaffold.yaml (paths, permissions, credentials)","If the hook is best-effort cleanup, make the script tolerant (e.g. `|| true` / explicit exit 0) so builds aren't blocked"],"exampleFix":"// before (skaffold.yaml)\nbuild:\n  postHooks:\n    - exec: [\"bash\", \"./scripts/cleanup.sh\"]  # fails when artifacts absent\n// after (cleanup.sh)\nrm -rf ./.cache || true\nexit 0","handlingStrategy":"try-catch","validationCode":"// verify post-hook script tolerates missing artifacts\nsh(\"./scripts/cleanup.sh || echo 'post-hook would fail'\")","typeGuard":null,"tryCatchPattern":"try {\n  await run('skaffold build')\n} catch (err) {\n  if (/running builder post-hooks/.test(err.message)) {\n    console.error('post-hook failed (build itself succeeded):', err.cause ?? err.message)\n  }\n  throw err\n}","preventionTips":["Make post-hook cleanup scripts non-fatal (|| true, explicit exit 0)","Test post-hooks against both success and failure build outputs","Avoid registry/network calls in post-hooks without credential checks"],"tags":["build","hooks","lifecycle"],"backgroundTag":"build-hook-failed","analyzedSha":"a1189de023efc32d4b8e11f395acc678aa555011","analyzedAt":"2026-09-05T12:09:27.064Z","contentChangedAt":"2026-09-05T12:09:27.064Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}