GoogleContainerTools/skaffold · error

failed to build: %w

Error message

failed to build: %w

What it means

`skaffold run` builds all target artifacts first via `r.Build`; this wrapper reports a build failure and aborts run before testing/deploying. It means at least one artifact failed to build, so the full run (test → deploy) pipeline stops here.

Source

Thrown at cmd/skaffold/app/cmd/run.go:48

)

// NewCmdRun describes the CLI command to run a pipeline.
func NewCmdRun() *cobra.Command {
	return NewCmd("run").
		WithDescription("Run a pipeline").
		WithLongDescription("Run a pipeline: build and test artifacts, tag them, update Kubernetes manifests and deploy to a cluster.").
		WithExample("Build, test, deploy and tail the logs", "run --tail").
		WithExample("Run with a given profile", "run -p <profile>").
		WithCommonFlags().
		WithHouseKeepingMessages().
		NoArgs(doRun)
}

func doRun(ctx context.Context, out io.Writer) error {
	return withRunner(ctx, out, func(r runner.Runner, configs []util.VersionedConfig) error {
		bRes, err := r.Build(ctx, out, targetArtifacts(opts, configs))
		if err != nil {
			return fmt.Errorf("failed to build: %w", err)
		}

		if !opts.SkipTests {
			err = r.Test(ctx, out, bRes)
			if err != nil {
				return fmt.Errorf("failed to test: %w", err)
			}
		}

		// Render
		manifestList, err := r.Render(ctx, out, bRes, false)
		if err != nil {
			return fmt.Errorf("rendering manifests: %w", err)
		}
		if opts.RenderOnly {
			return manifest.Write(manifestList.String(), opts.RenderOutput, out)
		}

View on GitHub (pinned to a1189de023)

Solutions

  1. Run `skaffold build` alone to isolate and see the raw build error.
  2. Fix the underlying build problem indicated by the wrapped error (Dockerfile, deps, compile).
  3. Ensure registry authentication (docker login / credential helper) and the Docker daemon are available.
  4. Use `skaffold dev` interactively for faster iteration on build errors, or --cache-artifacts to leverage caching.

Example fix

# before: private base image without auth
FROM gcr.io/my-project/base:latest
# after: authenticate before skaffold run
gcloud auth configure-docker gcr.io
skaffold run
Defensive patterns

Strategy: try-catch

Validate before calling

// Pre-flight before skaffold run in CI
const fs = require('fs');
try { execSync('docker info', {stdio: 'ignore'}); } catch { throw new Error('Docker daemon unavailable'); }
if (!fs.existsSync('Dockerfile')) throw new Error('Dockerfile missing at repo root');
// isolate build first so run only fails on test/deploy issues
execFileSync('skaffold', ['build', '-q'], {stdio: 'pipe'});

Try / catch

try {
  execFileSync('skaffold', ['run'], {stdio: 'pipe'});
} catch (e) {
  const msg = e.stderr?.toString() ?? '';
  if (msg.includes('failed to build')) {
    console.error('skaffold run aborted at build; run `skaffold build` for the raw error:', msg);
    // fix Dockerfile/registry/compile issue, then retry
  } else throw e;
}

Prevention

When it happens

Trigger: `skaffold run` where the build phase fails: Dockerfile error, base image pull failure (auth or network), source compile error, buildkit cache issues, or a build dependency (gradle/maven/npm) failing.

Common situations: CI pipelines running skaffold run without registry credentials; missing Docker daemon in the CI runner; code that doesn't compile; private base images not pullable; port/file locks during concurrent builds.

Related errors


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