Gradle Jib / bootBuildImage Failure - Fix Image Build in CI
A Gradle container-image build with the Jib plugin (jib) or Spring Boot’s bootBuildImage failed. As with Maven, the usual causes are registry authentication (401/403), an unreachable base image, or - for bootBuildImage - no Docker daemon for the buildpacks builder. Pure base-image pulls can blip transiently.
What this error means
The jib/bootBuildImage task fails with Build image failed, Unauthorized (401)/403 Forbidden, Connection to the Docker daemon ... failed, or a base-image pull timeout. Compile and test passed; only the image step failed.
> Task :app:jib FAILED
com.google.cloud.tools.jib.plugins.common.BuildStepsExecutionException:
Build image failed, perhaps you should make sure your credentials for
'registry.example.com/app' are set up correctly. Unauthorized (401)Common causes
Registry authentication missing or wrong
Jib pushes (and may pull a private base) using credential helpers or to/from auth. Absent or stale CI credentials produce 401/403.
No Docker daemon for bootBuildImage, or a base-image pull failure
bootBuildImage runs buildpacks against a Docker daemon - none available means a daemon-connection failure. An unreachable base-image registry can also time out the pull (often transient).
How to fix it
Supply registry credentials in CI
Provide auth for source and target registries via task config or -P/environment.
jib {
from { image = "eclipse-temurin:21-jre" }
to {
image = "registry.example.com/app:latest"
auth {
username = System.getenv("REG_USER")
password = System.getenv("REG_TOKEN")
}
}
}Ensure a Docker daemon for bootBuildImage (or use jib registry push)
bootBuildImage needs Docker; Jib’s jib task pushes to a registry without a daemon.
docker info >/dev/null # bootBuildImage needs this to succeed
./gradlew bootBuildImage
# OR daemonless registry push:
./gradlew jibHow to prevent it
- Inject registry credentials from CI secrets for both
fromandto. - Prefer the daemonless
jibtask in CI over Docker-dependentbootBuildImage. - Pin and mirror base images to reduce dependence on a public registry.