From 699da7f196d68b5d1283be8bc1073f15ee1f356b Mon Sep 17 00:00:00 2001
From: Felix <felix.ohms@gmx.de>
Date: Mon, 15 Nov 2021 18:29:54 +0100
Subject: [PATCH] Add rules for integration tests

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

diff --git a/.gitlab/ci/.containerlab-ci.yml b/.gitlab/ci/.containerlab-ci.yml
index 7123202ce..6eeea4f8f 100644
--- a/.gitlab/ci/.containerlab-ci.yml
+++ b/.gitlab/ci/.containerlab-ci.yml
@@ -4,6 +4,15 @@ variables:
   CLAB_DIR: "/mnt"
   CLAB_NAME: "clab${CI_PIPELINE_IID}"
 
+.integration_test_conditions:
+  rules:
+    - if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
+      when: always
+    - if: '$CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "develop"'
+      when: always
+    - if: '$CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master"'
+      when: always
+
 # Templates for Job Types
 .containerlab_deploy: &containerlab_deploy
   stage: apply
@@ -65,6 +74,9 @@ containerlab:deploy:integration:
   artifacts:
     reports:
       dotenv: ${CI_PROJECT_DIR}/build.env
+  rules:
+    - !reference [.integration_test_conditions, rules]
+
 
 
 containerlab:destroy:
@@ -79,7 +91,8 @@ containerlab:destroy:
     - docker volume rm -f ${CLAB_NAME}-volume
     - docker image rm -f ${GOSDN_CONTAINER_IMAGE}
   allow_failure: true
-  when: always
+  rules:
+    - !reference [.integration_test_conditions, rules]
 
 
 #containerlab:template:develop:
-- 
GitLab