{"record":{"id":"b24ccb1544026874","repo":"spring-projects/spring-boot","slug":"invalid-value-for-option-environment-expected","errorCode":null,"errorMessage":"Invalid value for option '--environment'. Expected 'NAME=VALUE' but got '{}'.","messagePattern":"Invalid value for option '--environment'\\. Expected 'NAME=VALUE' but got '(.+?)'\\.","errorType":"validation","errorClass":"InvalidUserDataException","httpStatus":null,"severity":"error","filePath":"build-plugin/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootBuildImage.java","lineNumber":119,"sourceCode":"\t\tgetCleanCache().convention(false);\n\t\tgetVerboseLogging().convention(false);\n\t\tgetPublish().convention(false);\n\t\tthis.buildWorkspace = getProject().getObjects().newInstance(LocalCacheSpec.class);\n\t\tthis.buildCache = getProject().getObjects().newInstance(CacheSpec.class);\n\t\tthis.launchCache = getProject().getObjects().newInstance(LocalCacheSpec.class);\n\t\tthis.docker = getProject().getObjects().newInstance(DockerSpec.class);\n\t\tthis.pullPolicy = getProject().getObjects().property(PullPolicy.class);\n\t\tgetSecurityOptions().convention((Iterable<? extends String>) null);\n\t\tgetEffectiveEnvironment().putAll(getEnvironment());\n\t\tgetEffectiveEnvironment().putAll(getEnvironmentFromCommandLine().map(BootBuildImage::asMap));\n\t}\n\n\tprivate static Map<String, String> asMap(List<String> variables) {\n\t\tMap<String, String> environment = new LinkedHashMap<>();\n\t\tfor (String variable : variables) {\n\t\t\tint index = variable.indexOf('=');\n\t\t\tif (index <= 0) {\n\t\t\t\tthrow new InvalidUserDataException(\n\t\t\t\t\t\t\"Invalid value for option '--environment'. Expected 'NAME=VALUE' but got '\" + variable + \"'.\");\n\t\t\t}\n\t\t\tString name = variable.substring(0, index);\n\t\t\tString value = variable.substring(index + 1);\n\t\t\tenvironment.put(name, value);\n\t\t}\n\t\treturn environment;\n\t}\n\n\t/**\n\t * Returns the property for the archive file from which the image will be built.\n\t * @return the archive file property\n\t */\n\t@InputFile\n\t@PathSensitive(PathSensitivity.RELATIVE)\n\tpublic abstract RegularFileProperty getArchiveFile();\n\n\t/**","sourceCodeStart":101,"sourceCodeEnd":137,"githubUrl":"https://github.com/spring-projects/spring-boot/blob/270dfe353fb830fd69b823a8a859287ff103854b/build-plugin/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootBuildImage.java#L101-L137","documentation":"Thrown by BootBuildImage.asMap when parsing command-line '--environment' option values. Each value must be of the form 'NAME=VALUE'. The code finds the index of '=' and throws InvalidUserDataException if the index is <= 0, meaning either there is no '=' at all, or the name is empty (e.g. '=VALUE'). This is a user input validation error at option-parsing time.","triggerScenarios":"Passing '--environment FOO' (missing '=value'), '--environment =bar' (empty name), or '--environment FOO_BAR' (no equals sign) to the bootBuildImage task on the Gradle command line or in the task's environment configuration.","commonSituations":"Typing an env var without a value separator. Copying an env var from a shell 'export FOO' syntax into the Gradle option. Using a space instead of '='. Setting an env var name that is empty. Common when scripting bootBuildImage in CI.","solutions":["Ensure every --environment value is 'NAME=VALUE' with a non-empty NAME: e.g. '--environment BP_JVM_VERSION=21'.","If setting multiple, repeat the flag: '--environment BP_JVM_VERSION=21 --environment BPE_DEBUG=true'.","Quote values containing spaces or special characters: '--environment \"BPE_GREETING=hello world\"'.","Validate env var strings programmatically before passing them if generating them in a script."],"exampleFix":"// before\ngradle bootBuildImage --environment BP_JVM_VERSION\n// after\ngradle bootBuildImage --environment BP_JVM_VERSION=21","handlingStrategy":"validation","validationCode":"// Validate environment strings before passing them to the task.\nvoid validateEnvVars(List<String> vars) {\n    for (String v : vars) {\n        int idx = v.indexOf('=');\n        if (idx <= 0) {\n            throw new IllegalArgumentException(\"Invalid env var (expected NAME=VALUE): \" + v);\n        }\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always use 'NAME=VALUE' format for --environment options.","In CI scripts, validate env var strings before invoking gradle.","Quote values containing spaces or special characters."],"tags":["gradle","validation","build-image","environment","command-line","configuration"],"backgroundTag":null,"analyzedSha":"270dfe353fb830fd69b823a8a859287ff103854b","analyzedAt":"2026-08-11T19:42:06.541Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}