diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index f45e9990819065403a598e2a2fdc8ac5b6036e62..5180c6f663b550c9013b729d7c2a6c04c477ada3 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -22,12 +22,10 @@ build_containers:
   script:
     # Find the directories that contain a file named 'Dockerfile'
     - |
-      set -x
-      set -e
       find . -name Dockerfile -type f | while read FILE;
       do
           # Strip leading './' and trailing '/<filename>'
-          DOCKER_DIR=$(echo "${FILE}" | sed -r 's|^\./||' | dirname)
+          DOCKER_DIR=$(echo "${FILE}" | sed -r 's|^\./||' | xargs dirname)
           if grep -q "^${DOCKER_DIR}" changed_files.log;
           then
               echo "Detected a changed file inside ./${DOCKER_DIR}/. (Re)build the container."