diff --git a/gitlab/before_docs.sh b/gitlab/before_docs.sh
index ca031af511ed7dc9fded8be01de9986daa693b32..71679c5abad81486fdafb2d008f047444bfb42d4 100755
--- a/gitlab/before_docs.sh
+++ b/gitlab/before_docs.sh
@@ -3,6 +3,12 @@
 
 source $(dirname ${0})/functions.sh
 
+# if the docs will be uploaded to at least one place,
+# make sure that the project folder will be available
+if [[ ${#DOC_UPLOADS[@]} -gt 0 ]]; then
+  dav_recursive_mkdir "${DOC_SERVER_PREFIX}"
+fi
+
 # Deletes all existing dav folders that will be overwritten
 for k in "${DOC_UPLOADS[@]}"; do
   dav_delete "${k}"
diff --git a/gitlab/functions.sh b/gitlab/functions.sh
index 2d7cccc6b2a6b4ee155db680165368e7417c8874..5205a4e6175fb631fbc315acd0ce9ddf6f7587d8 100644
--- a/gitlab/functions.sh
+++ b/gitlab/functions.sh
@@ -472,11 +472,5 @@ if [[ -n "${CI_COMMIT_TAG}" && "${IS_MASTER}" == "true" ]]; then
   DOC_UPLOADS+=("${DOC_SERVER_PREFIX}/stable/")
 fi
 
-# if the docs will be uploaded to at least one place,
-# make sure that the project folder will be available
-if [[ ${#DOC_UPLOADS[@]} -gt 0 ]]; then
-  dav_recursive_mkdir "${DOC_SERVER_PREFIX}"
-fi
-
-unset DOC_SERVER_PREFIX
+export_env DOC_SERVER_PREFIX
 check_env DOC_UPLOADS