From bfe2d6734610cd0b017e001abaaa986d605bacd3 Mon Sep 17 00:00:00 2001 From: Gerrit Date: Tue, 11 Jun 2024 15:41:45 +0200 Subject: [PATCH] Fix containerlab CI cleanup when no containers are running. --- test/ci-cleanup.sh | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/test/ci-cleanup.sh b/test/ci-cleanup.sh index 224a5f00..7eb15589 100755 --- a/test/ci-cleanup.sh +++ b/test/ci-cleanup.sh @@ -4,11 +4,15 @@ set -e echo "Cleanup artifacts of previous runs" # containerlab will figure out previous run locations from the docker containers -previous_topos=$(docker inspect -f '{{ index .Config.Labels "clab-topo-file" }}' $(docker ps -aq)) -for topo in previous_topos; do - previous_lab_dir=$(dirname $topo) - mkdir -p "${previous_lab_dir}/clab-mini-lab" -done +running_containers=$(docker ps -aq) + +if [ ! -z "$running_containers" ]; then + previous_topos=$(docker inspect -f '{{ index .Config.Labels "clab-topo-file" }}' $(docker ps -aq)) + for topo in previous_topos; do + previous_lab_dir=$(dirname $topo) + mkdir -p "${previous_lab_dir}/clab-mini-lab" + done +fi make cleanup