From 3e948f5db0c926a1226746fd597b5a53163a0796 Mon Sep 17 00:00:00 2001
From: Tim Jaacks <tim.jaacks@garz-fricke.com>
Date: Tue, 29 Mar 2022 19:16:13 +0200
Subject: [PATCH] manifest: check if docker build folder is empty

BCS DevOps-000035
---
 manifest-build.yml | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/manifest-build.yml b/manifest-build.yml
index 52c22fde..6d421573 100644
--- a/manifest-build.yml
+++ b/manifest-build.yml
@@ -9,6 +9,19 @@ variables:
   GIT_BASE_URL: "git@${CI_SERVER_HOST}:${CI_PROJECT_ROOT_NAMESPACE}"
   TESTS_GIT_URL: "${GIT_BASE_URL}/yocto/tests.git"
 
+.docker_check: &docker_check
+  # Check if the build folder is empty. Sometimes the docker volume for the build is not
+  # removed afterwards (e.g. in case of a timeout), then a follow-up build might fail.
+  - |-
+    if [ "$(ls -A)" ]; then
+        echo "ERROR: Build folder is not empty. This might be the case because the" \
+             "docker volume has not been not removed in a previous job. Please check" \
+             "the docker container \"$CI_JOB_IMAGE\" on the GitLab runner" \
+             "\"$CI_RUNNER_SHORT_TOKEN\" ($CI_RUNNER_DESCRIPTION) and remove any" \
+             "attached volumes from it."
+        exit 1
+    fi
+
 .setup_ssh: &setup_ssh
   # setup ssh key to access private repos
   # https://docs.gitlab.com/ee/ci/ssh_keys/#ssh-keys-when-using-the-docker-executor
@@ -81,6 +94,7 @@ variables:
     INSTALLSCRIPTS: "fng-install.sh fngsystem-self-update.sh"
     BITBAKE_TASK: "build"
   before_script:
+    - *docker_check
     - *setup_ssh
     - *repo_checkout
   script:
-- 
GitLab