{"record":{"id":"0d7e8b5bf5506485","repo":"GoogleContainerTools/skaffold","slug":"inspect-build-env-already-exists-err","errorCode":"INSPECT_BUILD_ENV_ALREADY_EXISTS_ERR","errorMessage":"trying to create a %q build environment definition that already exists, in file %s (or, with profile: trying to create a %q build environment definition that already exists, in profile %q in file %s)","messagePattern":"trying to create a %q build environment definition that already exists, in file (.+?) \\(or, with profile: trying to create a %q build environment definition that already exists, in profile %q in file (.+?)\\)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/skaffold/inspect/errors.go","lineNumber":35,"sourceCode":"package inspect\n\nimport (\n\t\"errors\"\n\t\"fmt\"\n\n\tsErrors \"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/errors\"\n\t\"github.com/GoogleContainerTools/skaffold/v2/proto/v1\"\n)\n\n// BuildEnvAlreadyExists specifies that there's an existing build environment definition for the same type.\nfunc BuildEnvAlreadyExists(b BuildEnv, filename string, profile string) error {\n\tvar msg string\n\tif profile == \"\" {\n\t\tmsg = fmt.Sprintf(\"trying to create a %q build environment definition that already exists, in file %s\", b, filename)\n\t} else {\n\t\tmsg = fmt.Sprintf(\"trying to create a %q build environment definition that already exists, in profile %q in file %s\", b, profile, filename)\n\t}\n\treturn sErrors.NewError(errors.New(msg),\n\t\t&proto.ActionableErr{\n\t\t\tMessage: msg,\n\t\t\tErrCode: proto.StatusCode_INSPECT_BUILD_ENV_ALREADY_EXISTS_ERR,\n\t\t\tSuggestions: []*proto.Suggestion{\n\t\t\t\t{\n\t\t\t\t\tSuggestionCode: proto.SuggestionCode_INSPECT_USE_MODIFY_OR_NEW_PROFILE,\n\t\t\t\t\tAction:         \"Use the `modify` command instead of the `add` command to overwrite fields for an already existing build environment type. Otherwise pass the `--profile` flag with a unique name to create the new build environment definition in a new profile instead\",\n\t\t\t\t},\n\t\t\t},\n\t\t})\n}\n\n// BuildEnvNotFound specifies that the target build environment definition doesn't exist.\nfunc BuildEnvNotFound(b BuildEnv, filename string, profile string) error {\n\tvar msg string\n\tif profile == \"\" {\n\t\tmsg = fmt.Sprintf(\"trying to modify a %q build environment definition that doesn't exist, in file %s\", b, filename)\n\t} else {","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/GoogleContainerTools/skaffold/blob/a1189de023efc32d4b8e11f395acc678aa555011/pkg/skaffold/inspect/errors.go#L17-L53","documentation":"BuildEnvAlreadyExists is returned by the skaffold inspect 'add build env' API (AddClusterBuildEnv, AddGcbBuildEnv, AddLocalBuildEnv) when a build environment of the requested type already exists in the target skaffold.yaml file, or within the given profile. It carries code INSPECT_BUILD_ENV_ALREADY_EXISTS_ERR and a suggestion to use modify or a new profile instead of adding a duplicate.","triggerScenarios":"Calling a build-env add mutation (e.g. via `skaffold inspect add build-env` or the inspect API) targeting a file/profile that already contains a build env of the same type, while the mutation only allows one definition per type.","commonSituations":"Rerunning an automation script that adds a build env without idempotency; target file already configured with the same builder type; adding to a profile that inherits or defines the same env; pointing --filename at the wrong file.","solutions":["Use `skaffold inspect modify build-env` instead of add to update the existing definition","Target a new or different profile so the add is not a duplicate","Inspect the current state first (`skaffold inspect build-envs --filename ... [--profile ...]`) and remove the duplicate if unwanted","Make scripts idempotent: check existence before calling add"],"exampleFix":"// before\nskaffold inspect add build-env --type cluster --filename skaffold.yaml  # already exists\n// after\nskaffold inspect modify build-env --type cluster \\\n  --namespace new-ns --filename skaffold.yaml\n# or add into a fresh profile:\nskaffold inspect add build-env --type cluster \\\n  --profile ci --filename skaffold.yaml","handlingStrategy":"validation","validationCode":"envs, err := inspect.ListBuildEnvs(filename, profile)\nif err == nil {\n    for _, e := range envs {\n        if e.Type == \"cluster\" {\n            return errors.New(\"cluster build env already exists; use modify instead of add\")\n        }\n    }\n}","typeGuard":null,"tryCatchPattern":"err := skaffoldInspect(\"add\", \"build-env\", \"--type\", \"cluster\")\nif err != nil && strings.Contains(err.Error(), \"already exists\") {\n    // fall back to modify\n    err = skaffoldInspect(\"modify\", \"build-env\", \"--type\", \"cluster\")\n}","preventionTips":["Check existing build-envs with `skaffold inspect build-envs` before adding","Make provisioning scripts idempotent (add only if type absent)","Target distinct profiles per environment definition"],"tags":["skaffold","inspect","configuration","build-env"],"backgroundTag":"duplicate-config-definition","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"}