GoogleContainerTools/skaffold · error

running builder pre-hooks: %w

Error message

running builder pre-hooks: %w

What it means

pipelineBuilderWithHooks.PreBuild runs the underlying builder's PreBuild, then executes the user-configured build pre-hooks. If any pre-hook command fails, the error is wrapped as "running builder pre-hooks: %w" so the hook's own failure output is preserved in the chain.

Source

Thrown at pkg/skaffold/runner/builder.go:93

	default:
		return nil, fmt.Errorf("unknown builder for config %+v", p.Build)
	}
}

type pipelineBuilderWithHooks struct {
	build.PipelineBuilder
	hooksRunner hooks.Runner
}

// PreBuild executes any one-time setup required prior to starting any build on this builder,
// followed by any Build pre-hooks set for the pipeline.
func (b *pipelineBuilderWithHooks) PreBuild(ctx context.Context, out io.Writer) error {
	if err := b.PipelineBuilder.PreBuild(ctx, out); err != nil {
		return err
	}

	if err := b.hooksRunner.RunPreHooks(ctx, out); err != nil {
		return fmt.Errorf("running builder pre-hooks: %w", err)
	}

	return nil
}

// PostBuild executes any one-time teardown required after all builds on this builder are complete,
// followed by any Build post-hooks set for the pipeline.
func (b *pipelineBuilderWithHooks) PostBuild(ctx context.Context, out io.Writer) error {
	if err := b.PipelineBuilder.PostBuild(ctx, out); err != nil {
		return err
	}

	if err := b.hooksRunner.RunPostHooks(ctx, out); err != nil {
		return fmt.Errorf("running builder post-hooks: %w", err)
	}

	return nil
}

View on GitHub (pinned to a1189de023)

Solutions

  1. Read the wrapped underlying error and fix the failing pre-hook command in skaffold.yaml
  2. Run the hook command manually in your shell to reproduce and debug it
  3. Ensure hook scripts are executable and available on PATH (chmod +x, correct shebang)

Example fix

// before (skaffold.yaml)
build:
  preHooks:
    - exec: ./scripts/generate.sh   # not executable
// after
chmod +x ./scripts/generate.sh
# and pin interpreter explicitly:
build:
  preHooks:
    - exec: ["bash", "./scripts/generate.sh"]
Defensive patterns

Strategy: try-catch

Validate before calling

// smoke-test pre-hooks before building
sh("bash -n scripts/generate.sh && ./scripts/generate.sh --dry-run")

Try / catch

try {
  await run('skaffold build')
} catch (err) {
  if (/running builder pre-hooks/.test(err.message)) {
    // surface the wrapped hook error and rerun hooks manually for debugging
    console.error('pre-hook failed:', err.cause ?? err.message)
  }
  throw err
}

Prevention

When it happens

Trigger: A `build.preHooks` (or lifecycle pre-build hooks) command defined in skaffold.yaml exits non-zero during a `skaffold build`/`dev`/`run` invocation.

Common situations: Pre-hook scripts that generate code or download dependencies failing due to missing tools (not on PATH), network failures, or non-portable shell commands on the developer's OS.

Related errors


AI-assisted analysis of GoogleContainerTools/skaffold@a1189de023 (2026-09-05). Data as JSON: /api/errors/64953b42a693b886. Report an issue: GitHub.