From f1c158b94017a0819ed6de018310f95adc4e0e61 Mon Sep 17 00:00:00 2001
From: Felix <felix.ohms@gmx.de>
Date: Thu, 4 Nov 2021 16:19:16 +0100
Subject: [PATCH] check necessity via return code variable assignment

---
 .gitlab/ci/.containerlab-ci.yml | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/.gitlab/ci/.containerlab-ci.yml b/.gitlab/ci/.containerlab-ci.yml
index d52db597a..e710810be 100644
--- a/.gitlab/ci/.containerlab-ci.yml
+++ b/.gitlab/ci/.containerlab-ci.yml
@@ -3,6 +3,7 @@ variables:
   GOSDN_CONTAINER_IMAGE: "${CI_REGISTRY_IMAGE}:${CI_COMMIT_SHA}"
   CLAB_DIR: "/mnt"
   CLAB_NAME: "clab${CI_PIPELINE_IID}"
+  CLAB_DEPLOYED: 1
 
 # Templates for Job Types
 .containerlab_deploy: &containerlab_deploy
@@ -50,6 +51,7 @@ containerlab:deploy:integration:
   needs: ["containerlab:template:integration", "build-docker"]
   script:
     - sudo containerlab deploy --topo ${CI_PROJECT_DIR}/${CLAB_NAME}.clab.yml --reconfigure
+    - CLAB_DEPLOYED = $?
     - |
       echo -e "\
       GOSDN_HTTP_PORT=$(docker_host_port 8080 clab-${CLAB_NAME}-gosdn)\n\
@@ -73,7 +75,9 @@ containerlab:destroy:
     - docker volume rm -f ${CLAB_NAME}-volume
     - docker image rm -f ${GOSDN_CONTAINER_IMAGE}
   allow_failure: true
-  when: always
+  rules:
+    - if: '$CLAB_DEPLOYED == 0'
+      when: always
 
 
 #containerlab:template:develop:
-- 
GitLab