Check that variables for exit actions are defined 21/112621/3
authorLasse Kaihlavirta <l.kaihlavirt@partner.samsung.com>
Mon, 14 Sep 2020 14:57:56 +0000 (17:57 +0300)
committerLasse Kaihlavirta <l.kaihlavirt@partner.samsung.com>
Mon, 14 Sep 2020 15:15:03 +0000 (18:15 +0300)
 - Check that $WORKSPACE and $WORKDIR variables are defined before
   using them on exit actions to prevent inappropriate behaviour
   on early failures (such as non-existent plans directory)

Issue-ID: INT-1721
Signed-off-by: Lasse Kaihlavirta <l.kaihlavirt@partner.samsung.com>
Change-Id: I9771aae634efdbd5c571ab9e05de7886d8a07993

run-csit.sh

index 634b0c7..52d1693 100755 (executable)
 
 function on_exit(){
     rc=$?
-    rsync -av "$WORKDIR/" "$WORKSPACE/archives"
-
-    # Record list of active docker containers
-    docker ps --format "{{.Image}}" > "$WORKSPACE/archives/_docker-images.log"
-
-    # show memory consumption after all docker instances initialized
-    docker_stats | tee "$WORKSPACE/archives/_sysinfo-2-after-robot.txt"
-
+    if [[ ${WORKSPACE} ]]; then
+        if [[ ${WORKDIR} ]]; then
+            rsync -av "$WORKDIR/" "$WORKSPACE/archives"
+        fi
+        # Record list of active docker containers
+        docker ps --format "{{.Image}}" > "$WORKSPACE/archives/_docker-images.log"
+
+        # show memory consumption after all docker instances initialized
+        docker_stats | tee "$WORKSPACE/archives/_sysinfo-2-after-robot.txt"
+    fi
     # Run teardown script plan if it exists
     cd "${TESTPLANDIR}"
     TEARDOWN="${TESTPLANDIR}/teardown.sh"