diff --git a/.buildkite/daily.yml b/.buildkite/daily.yml
index 4f21fd29f57..c5fc99e8e1f 100644
--- a/.buildkite/daily.yml
+++ b/.buildkite/daily.yml
@@ -27,15 +27,8 @@ steps:
- junit-annotate#v1.7.0:
artifacts: twister-*.xml
- - command: |
- buildkite-agent artifact download twister-*.xml .
- junitparser merge twister-*.xml junit.xml
- buildkite-agent artifact upload junit.xml
- junit2html junit.xml
- buildkite-agent artifact upload junit.xml.html
- cat << EOF | buildkite-agent annotate --style "info"
- Read the JUnit test report
- EOF
+ - command:
+ - .buildkite/mergejunit.sh
notify:
- email: "builds+int+399+7809482394022958124@lists.zephyrproject.org"
diff --git a/.buildkite/mergejunit.sh b/.buildkite/mergejunit.sh
new file mode 100755
index 00000000000..17ac9f137a7
--- /dev/null
+++ b/.buildkite/mergejunit.sh
@@ -0,0 +1,19 @@
+#!/bin/bash
+# Copyright (c) 2021 Linaro Limited
+#
+# SPDX-License-Identifier: Apache-2.0
+set -eE
+
+buildkite-agent artifact download twister-*.xml .
+
+xmls=""
+
+for f in twister-*xml; do [ -s ${f} ] && xmls+="${f} "; done
+
+if [ "${xmls}" ]; then
+ junitparser merge ${xmls} junit.xml
+ buildkite-agent artifact upload junit.xml
+ junit2html junit.xml
+ buildkite-agent artifact upload junit.xml.html
+ buildkite-agent annotate --style "info" "Read the JUnit test report"
+fi
diff --git a/.buildkite/pipeline.yml b/.buildkite/pipeline.yml
index 9f06e7daf47..1f9be61d1a3 100644
--- a/.buildkite/pipeline.yml
+++ b/.buildkite/pipeline.yml
@@ -27,12 +27,5 @@ steps:
- junit-annotate#v1.7.0:
artifacts: twister-*.xml
- - command: |
- buildkite-agent artifact download twister-*.xml .
- junitparser merge twister-*.xml junit.xml
- buildkite-agent artifact upload junit.xml
- junit2html junit.xml
- buildkite-agent artifact upload junit.xml.html
- cat << EOF | buildkite-agent annotate --style "info"
- Read the JUnit test report
- EOF
+ - command:
+ - .buildkite/mergejunit.sh