From 50849de3a3e9e6694fa1d36391a38487f848dc63 Mon Sep 17 00:00:00 2001
From: Eleni Mathioulaki <emathioulaki@athenarc.gr>
Date: Sun, 24 Sep 2023 15:17:34 +0200
Subject: [PATCH] minor fix in artifact collection

---
 .gitlab-ci.yml | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 3ce39d47..f38951c6 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -205,11 +205,10 @@ build-spack-env-on-runner:
   after_script:
     - mkdir -p $CI_PROJECT_DIR/spack_logs/installed $CI_PROJECT_DIR/spack_logs/not_installed
       # for succesfully installed packages: keep the spack logs for any package modified during this CI job
-    - cd $SPACK_DEV_PATH/opt/spack/linux-ubuntu20.04-x86_64/gcc-10.3.0
-    - find . \( -name ".spack" -o -name ".spack_test_results" -o -name ".build" \) -exec cp -r --parents "{}" $CI_PROJECT_DIR/spack_logs/installed \;
+    - PKG_DIR=$SPACK_DEV_PATH/opt/spack/linux-ubuntu20.04-x86_64/gcc-10.3.0
+    - if cd $PKG_DIR; then find . \( -name ".spack" -o -name ".build" -o -name ".spack_test_results" \) -exec cp -r --parents "{}" $CI_PROJECT_DIR/spack_logs/installed \;; fi
       # for not succesfully installed packages: also keep the spack logs for any packages that failed
-    - cd /tmp/$(whoami)/spack-stage/
-    - find . -maxdepth 2 -name "*.txt" -exec cp --parents "{}" $CI_PROJECT_DIR/spack_logs/not_installed \;
+    - if cd /tmp/$(whoami)/spack-stage/; then find . -maxdepth 2 -name "*.txt" -exec cp --parents "{}" $CI_PROJECT_DIR/spack_logs/not_installed \;; fi
   artifacts:
     paths:
       - spack_logs
@@ -277,11 +276,10 @@ sync-gitlab-spack-instance:
     - mkdir -p $CI_PROJECT_DIR/spack_logs/installed $CI_PROJECT_DIR/spack_logs/not_installed
       # for succesfully installed packages: keep the spack logs for any package modified during this CI job
       # (we use repo.yaml, that is modified at each start of the pipeline, as a reference file)
-    - cd $SPACK_PATH/spack/opt/spack/linux-ubuntu20.04-x86_64/gcc-10.3.0
-    - find . \( -name ".spack" -o -name ".spack_test_results" -o -name ".build" \) -newer $SPACK_REPO_PATH/repo.yaml -exec cp -r --parents "{}" $CI_PROJECT_DIR/spack_logs/installed \;
+    - PKG_DIR=$SPACK_PATH/spack/opt/spack/linux-ubuntu20.04-x86_64/gcc-10.3.0
+    - if cd $PKG_DIR; then find . -newer $SPACK_REPO_PATH/repo.yaml \( -name ".spack" -o -name ".spack_test_results" -o -name ".build" \) -exec cp -r --parents "{}" $CI_PROJECT_DIR/spack_logs/installed \;; fi
       # for not succesfully installed packages: also keep the spack logs for any packages that failed
-    - cd /tmp/$(whoami)/spack-stage/
-    - find . -maxdepth 2 -name "*.txt" -exec cp --parents "{}" $CI_PROJECT_DIR/spack_logs/not_installed \;
+    - if cd /tmp/$(whoami)/spack-stage/; then find . -maxdepth 2 -name "*.txt" -exec cp --parents "{}" $CI_PROJECT_DIR/spack_logs/not_installed \;; fi
   artifacts:
     paths:
       - spack_logs
-- 
GitLab