From 60e6301fbdc2f05551efd1cb12a2a2cd102f8254 Mon Sep 17 00:00:00 2001 From: Tobias Gesellchen Date: Mon, 7 Feb 2022 21:20:07 +0100 Subject: [PATCH] Errors during docker build should make the DockerBuildTask fail Closes #195 --- .../gradle/docker/tasks/DockerBuildTask.java | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/plugin/src/main/java/de/gesellix/gradle/docker/tasks/DockerBuildTask.java b/plugin/src/main/java/de/gesellix/gradle/docker/tasks/DockerBuildTask.java index be761d69..10c82079 100644 --- a/plugin/src/main/java/de/gesellix/gradle/docker/tasks/DockerBuildTask.java +++ b/plugin/src/main/java/de/gesellix/gradle/docker/tasks/DockerBuildTask.java @@ -244,14 +244,26 @@ public void onFinished() { actualBuildContext); try { getLogger().debug("Waiting " + buildTimeout + " for the build to finish..."); - buildFinished.await(buildTimeout.toMillis(), TimeUnit.MILLISECONDS); + boolean finished = buildFinished.await(buildTimeout.toMillis(), TimeUnit.MILLISECONDS); + if (!finished) { + getLogger().error("Build didn't finish before timeout of " + buildTimeout); + return null; + } + + if (BuildInfoExtensionsKt.hasError(infos)) { + BuildInfo error = BuildInfoExtensionsKt.getError(infos); + getLogger().error("Build failed. {}", error != null ? error.getErrorDetail() : null); + return null; + } + + ImageID imageId = BuildInfoExtensionsKt.getImageId(infos); + this.imageId = imageId == null ? null : imageId.getID(); + return this.imageId; } catch (InterruptedException e) { - getLogger().error("Build didn't finish before timeout of " + buildTimeout, e); + getLogger().error("Build interrupted before timeout of " + buildTimeout, e); + return null; } - ImageID imageId = BuildInfoExtensionsKt.getImageId(infos); - this.imageId = imageId == null ? null : imageId.getID(); - return this.imageId; } @Internal