+function on_exit(){
+ rc=$?
+ if [[ ${WORKSPACE} ]]; then
+ if [[ ${WORKDIR} ]]; then
+ rsync -av "$WORKDIR/" "$WORKSPACE/archives/$TESTPLAN"
+ fi
+ # Record list of active docker containers
+ docker ps --format "{{.Image}}" > "$WORKSPACE/archives/$TESTPLAN/_docker-images.log"
+
+ # show memory consumption after all docker instances initialized
+ docker_stats | tee "$WORKSPACE/archives/$TESTPLAN/_sysinfo-2-after-robot.txt"
+ fi
+ # Run teardown script plan if it exists
+ cd "${TESTPLANDIR}"
+ TEARDOWN="${TESTPLANDIR}/teardown.sh"
+ if [ -f "${TEARDOWN}" ]; then
+ echo "Running teardown script ${TEARDOWN}"
+ source_safely "${TEARDOWN}"
+ fi
+ # TODO: do something with the output
+ exit $rc
+}
+# ensure that teardown and other finalizing steps are always executed
+trap on_exit EXIT
+