From d0a360ace377d2c9785af680638d77be334e330d Mon Sep 17 00:00:00 2001
From: Chase Qi <chase.qi@linaro.org>
Date: Wed, 6 Apr 2022 14:58:36 +0800
Subject: [PATCH] .oniro-ci: fail lava-report job if incomplete job found

Fail lava-report if incomplete job found. Allow lava-report to fail to
run the downstream lava-badage job.

Signed-off-by: Chase Qi <chase.qi@linaro.org>
---
 .oniro-ci/test-generic.yaml | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/.oniro-ci/test-generic.yaml b/.oniro-ci/test-generic.yaml
index f07e9bba..10155ebb 100644
--- a/.oniro-ci/test-generic.yaml
+++ b/.oniro-ci/test-generic.yaml
@@ -97,6 +97,8 @@
 
 .lava-report:
   interruptible: true
+  # Let the pipeline continue running 'lava-badge' job.
+  allow_failure: true
   image:
     name: registry.booting.oniroproject.org/distro/oniro/bitbake-builder:latest
   stage: report
@@ -105,6 +107,7 @@
     CI_LAVA_INSTANCE: "https://lava.ostc-eu.org/"
   script:
     - |
+      incomplete=false
       for file in $(find ./ -name "job_ids_*.txt"); do
         echo "Job file: $file"
         while read -r p; do
@@ -113,12 +116,17 @@
           # Echo LAVA job health and link.
           link="$CI_LAVA_INSTANCE/scheduler/job/$p"
           health="$(curl --silent "$CI_LAVA_INSTANCE/api/v0.2/jobs/$p/" | jq '.health' | tr -d '"')"
+          echo $health | grep -iq incomplete && incomplete=true
           echo "[$health] $link"
           # Get the JUnit export from LAVA.
           curl --silent -o job_$p.xml "$CI_LAVA_INSTANCE/api/v0.2/jobs/$p/junit/?classname_prefix=$p"
           echo "Report file: $(ls job_$p.xml)"
         done < "$file"
       done
+      if $incomplete; then
+        echo "ERROR: Incomplete test job reported: exit code 1"
+        exit 1
+      fi
   artifacts:
     when: always
     paths:
-- 
GitLab