From 8b5232a9bf982a2cc8822447cc1b322ed8cf3828 Mon Sep 17 00:00:00 2001
From: fredrfha <fredrfha@stud.ntnu.no>
Date: Sun, 16 Apr 2023 23:23:14 +0200
Subject: [PATCH] ci enable periodic heartbeat

---
 .gitlab-ci.yml | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 4d264cf..bae1c2f 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -121,15 +121,16 @@ VM Heartbeat:
     - |
       for i in {1..18}; do
         sleep 10
-        response=$(curl --silent --write-out "%{http_code}\n" --output /dev/null --connect-timeout 5 --max-time 10 http://10.212.26.72/server/heartbeat)
-        echo "Response: $response"
-        if [ "$response" -eq 200 ]; then
-          echo "Server is alive"
+        response_code=$(curl --silent --write-out "%{http_code}\n" --output response.txt --connect-timeout 5 --max-time 10 http://10.212.26.72/server/heartbeat)
+        response_body=$(cat response.txt)
+        echo "Response code: $response_code"
+        echo "Response body: $response_body"
+        if [ "$response_code" -eq 200 ]; then
           exit 0
         fi
       done
       echo "Server did not respond with 200 OK after 3 minutes"
       exit 1
-  only:
-    refs:
-      - main
\ No newline at end of file
+  rules:
+    - if: '$CI_COMMIT_BRANCH == "main"'
+    - if: '$CI_PIPELINE_SOURCE == "schedule" && $RUN_VM_HEARTBEAT == "true"'
\ No newline at end of file
-- 
GitLab