GoogleContainerTools/skaffold · error
writing build output to file
Error message
writing build output to file: %w
What it means
In `skaffold build` (cmd/skaffold/app/cmd/build.go:89), when --build-output is set, the rendered build results are written to the specified file via os.WriteFile with mode 0644. If writing the file fails, this error wraps the OS error.
Solutions
- Create the parent directory of the --build-output path before running (mkdir -p)
- Fix permissions on the target file/directory so the running user can write (chmod/chown)
- Point --build-output at a file path, not an existing directory
- Check available disk space and that the filesystem is not mounted read-only
Example fix
// before // skaffold build --build-output out/build.json # out/ does not exist // after // mkdir -p out && skaffold build --build-output out/build.json
Defensive patterns
Strategy: validation
Validate before calling
// Pre-flight the --build-output target before running
outPath := "out/build.json"
if dir := filepath.Dir(outPath); dir != "." {
if err := os.MkdirAll(dir, 0o755); err != nil {
return err
}
}
if fi, err := os.Stat(outPath); err == nil && fi.IsDir() {
return fmt.Errorf("--build-output target is a directory: %s", outPath)
} Try / catch
if err := sh.Run("skaffold", "build", "--build-output", outPath); err != nil {
if strings.Contains(err.Error(), "writing build output to file") {
log.Fatalf("cannot write %s: create parent dir and check permissions", outPath)
}
return err
} Prevention
- mkdir -p the output directory in the pipeline before building
- Use writable workspace paths in CI containers (not read-only mounts)
- Point --build-output at a file, never a directory
- Check free disk space in build jobs
When it happens
Trigger: Running `skaffold build --build-output <path>` where the path is unwritable: parent directory does not exist, permission denied on the target or directory, target path is a directory, or disk is full.
Common situations: CI script pointing --build-output at a directory that was never created; read-only filesystem or volume in the CI container; file owned by another user; path is an existing directory rather than a file.
Understand the failure class
Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.
Related errors
AI-assisted analysis of GoogleContainerTools/skaffold@a1189de023 (2026-09-05).
Data as JSON: /api/errors/081d5eadbfda4c74.
Report an issue: GitHub.
Appendix: source
Thrown at cmd/skaffold/app/cmd/build.go:89
return withRunner(ctx, out, func(r runner.Runner, configs []util.VersionedConfig) error {
bRes, err := r.Build(ctx, buildOut, targetArtifacts(opts, configs))
if quietFlag || buildOutputFlag != "" {
cmdOut := flags.BuildOutput{Builds: bRes}
var buildOutput bytes.Buffer
if err := buildFormatFlag.Template().Execute(&buildOutput, cmdOut); err != nil {
return fmt.Errorf("executing template: %w", err)
}
if quietFlag {
if _, err := out.Write(buildOutput.Bytes()); err != nil {
return fmt.Errorf("writing build output: %w", err)
}
}
if buildOutputFlag != "" {
if err := os.WriteFile(buildOutputFlag, buildOutput.Bytes(), 0644); err != nil {
return fmt.Errorf("writing build output to file: %w", err)
}
}
}
return err
})
}
func targetArtifacts(opts config.SkaffoldOptions, configs []util.VersionedConfig) []*latest.Artifact {
var targetArtifacts []*latest.Artifact
for _, cfg := range configs {
for _, artifact := range cfg.(*latest.SkaffoldConfig).Build.Artifacts {
if opts.IsTargetImage(artifact) {
targetArtifacts = append(targetArtifacts, artifact)
}
}
}
return targetArtifactsView on GitHub (pinned to a1189de023)