GoogleContainerTools/jib · error · BadContainerConfigurationFormatException
Invalid environment variable definition: + environmentVariab
Error message
Invalid environment variable definition: + environmentVariable
What it means
Each entry in the container configuration's 'Env' array must match ENVIRONMENT_PATTERN (NAME=value). Jib throws BadContainerConfigurationFormatException for entries that don't match, since it cannot split the variable name from its value.
Source
Thrown at jib-core/src/main/java/com/google/cloud/tools/jib/image/json/JsonToImageTranslator.java:210
builder.setRetries(containerConfigurationTemplate.getContainerHealthRetries());
}
imageBuilder.setHealthCheck(builder.build());
}
if (containerConfigurationTemplate.getContainerExposedPorts() != null) {
imageBuilder.addExposedPorts(
portMapToSet(containerConfigurationTemplate.getContainerExposedPorts()));
}
if (containerConfigurationTemplate.getContainerVolumes() != null) {
imageBuilder.addVolumes(volumeMapToSet(containerConfigurationTemplate.getContainerVolumes()));
}
if (containerConfigurationTemplate.getContainerEnvironment() != null) {
for (String environmentVariable : containerConfigurationTemplate.getContainerEnvironment()) {
Matcher matcher = ENVIRONMENT_PATTERN.matcher(environmentVariable);
if (!matcher.matches()) {
throw new BadContainerConfigurationFormatException(
"Invalid environment variable definition: " + environmentVariable);
}
imageBuilder.addEnvironmentVariable(matcher.group("name"), matcher.group("value"));
}
}
imageBuilder.addLabels(containerConfigurationTemplate.getContainerLabels());
imageBuilder.setWorkingDirectory(containerConfigurationTemplate.getContainerWorkingDir());
imageBuilder.setUser(containerConfigurationTemplate.getContainerUser());
}
/**
* Converts a map of exposed ports as strings to a set of {@link Port}s (e.g. {@code
* {"1000/tcp":{}}} -> {@code Port(1000, Protocol.TCP)}).
*
* @param portMap the map to convert
* @return a set of {@link Port}s
*/View on GitHub (pinned to fb949e2676)
Solutions
- Correct the offending Env entry to 'NAME=value' format in the container configuration JSON
- Pre-validate each entry against a NAME=value regex before calling toImage
- Catch BadContainerConfigurationFormatException, log the offending entry, and repair or drop it before retrying
Example fix
// before "Env": ["PATH"] // after "Env": ["PATH=/usr/local/bin:/usr/bin"]
Defensive patterns
Strategy: validation
Validate before calling
Pattern p = Pattern.compile("(?<name>[^=]+)=(?<value>.*)");
for (String env : config.getContainerEnvironment()) {
if (!p.matcher(env).matches()) throw new IllegalArgumentException("bad env entry: " + env);
} Try / catch
try { JsonToImageTranslator.toImage(manifest, config); } catch (BadContainerConfigurationFormatException e) { /* fix offending Env entry to NAME=value and retry */ } Prevention
- Ensure container config Env uses the Docker 'NAME=value' string array format
- Validate each entry contains '=' and a non-empty name
- Sanitize env arrays produced by non-Docker build tooling before translation
When it happens
Trigger: Calling JsonToImageTranslator.toImage with a container configuration whose environment entries lack '=', are empty strings, have an empty name, or contain malformed separators (e.g. 'NAME:' or 'NAME').
Common situations: Configs written by tooling that stores env as JSON objects instead of the Docker 'NAME=value' string array; hand-edited container config JSON; entries with only a name and no value; accidental whitespace or missing '=' after copy-paste.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
Related errors
- Diff ID not available for reference layer without diff ID
- Mismatch between image manifest and container configuration
- Invalid image creation time: + containerConfigurationTemplat
- Path does not start with forward slash (/): ${unixPath}
- Cannot create AbsoluteUnixPath from non-absolute Path: ${pat
AI-assisted analysis of GoogleContainerTools/jib@fb949e2676 (2026-09-06).
Data as JSON: /api/errors/c3a674044d7a4738.
Report an issue: GitHub.