GoogleContainerTools/skaffold · error

could not find latest tag for image %s in builds: %v

Error message

could not find latest tag for image %s in builds: %v

What it means

`NewItem` calls `latestTag(a.ImageName, builds)` to find the most recent build tag for the image being synced, and errors when no tag is found. It means the image being file-synced has no matching entry in the current builds list, so skaffold cannot determine which container/tag to sync into.

Source

Thrown at pkg/skaffold/sync/sync.go:67

var (
	WorkingDir = docker.RetrieveWorkingDir
	Labels     = docker.RetrieveLabels
	SyncMap    = syncMapForArtifact
)

func NewItem(ctx context.Context, a *latest.Artifact, e filemon.Events, builds []graph.Artifact, cfg docker.Config, dependentArtifactsCount int) (*Item, error) {
	if !e.HasChanged() || a.Sync == nil {
		return nil, nil
	}

	if dependentArtifactsCount > 0 {
		log.Entry(ctx).Warnf("Ignoring sync rules for image %q as it is being used as a required artifact for other images.", a.ImageName)
		return nil, nil
	}

	tag := latestTag(a.ImageName, builds)
	if tag == "" {
		return nil, fmt.Errorf("could not find latest tag for image %s in builds: %v", a.ImageName, builds)
	}

	switch {
	case len(a.Sync.Manual) > 0:
		return syncItem(ctx, a, tag, e, a.Sync.Manual, cfg)

	case a.Sync.Auto != nil:
		return autoSyncItem(ctx, a, tag, e, cfg)

	case len(a.Sync.Infer) > 0:
		return inferredSyncItem(ctx, a, tag, e, cfg)

	default:
		return nil, nil
	}
}

func syncItem(ctx context.Context, a *latest.Artifact, tag string, e filemon.Events, syncRules []*latest.SyncRule, cfg docker.Config) (*Item, error) {

View on GitHub (pinned to a1189de023)

Solutions

  1. Rebuild the artifact (restart `skaffold dev` or force a build) so its tag is present in the builds list.
  2. Ensure the artifact's ImageName in skaffold.yaml exactly matches the name used in builds (no typos/renames mid-session).
  3. If the image is built externally, make sure the builds list passed to NewItem includes its tag.
  4. Check active profiles don't exclude this artifact from the build phase.

Example fix

// before (renamed image mid-session)
build.artifacts: [{image: {imageName: "web-v2"}}] // builds contains "web"
// after
skaffold build && skaffold dev // rebuild so "web-v2" tag exists in builds
Defensive patterns

Strategy: validation

Validate before calling

func hasTag(builds []build.Artifact, image string) bool {
  for _, b := range builds {
    if b.ImageName == image && b.Tag != "" { return true }
  }
  return false
}
// only start dev / sync if hasTag(builds, artifact.ImageName)

Try / catch

item, err := sync.NewItem(ctx, artifact, events, builds, cfg)
if err != nil {
  if strings.Contains(err.Error(), "could not find latest tag") {
    log.Printf("image %s has no build yet; forcing build before sync", artifact.ImageName)
    return forceBuild(artifact)
  }
  return err
}

Prevention

When it happens

Trigger: Calling `NewItem` (during `skaffold dev` file change handling) with an artifact whose ImageName is absent from the `builds` slice — e.g. the artifact was never built, the image name was renamed in skaffold.yaml without rebuilding, or builds was passed empty.

Common situations: Editing `imageName` in skaffold.yaml mid-session so the saved file syncs an artifact that was built under a different name; dev session started with a profile that skips building this artifact; stale dev session after build cache was cleared; image built by another pipeline (e.g. CI) so no local build record exists.

Related errors


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