From 08b3e92662464794a4c39f032c13b24287b95c58 Mon Sep 17 00:00:00 2001 From: Anas Nashif Date: Fri, 4 Sep 2020 12:20:31 -0400 Subject: [PATCH] buildkite: trap errors and do proper cleanup On errors we were aborting immediately skipping any needed cleanup after the error has occured. This will run the cleanup function and upload reports of failure when something bad happens. Signed-off-by: Anas Nashif --- .buildkite/run.sh | 49 ++++++++++++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/.buildkite/run.sh b/.buildkite/run.sh index e1a9ba2ae9e..b8c8f6f3733 100755 --- a/.buildkite/run.sh +++ b/.buildkite/run.sh @@ -2,7 +2,34 @@ # Copyright (c) 2020 Linaro Limited # # SPDX-License-Identifier: Apache-2.0 -set -e +set -eE + +function cleanup() +{ + # Rename sanitycheck junit xml for use with junit-annotate-buildkite-plugin + # create dummy file if sanitycheck did nothing + if [ ! -f sanity-out/sanitycheck.xml ]; then + touch sanity-out/sanitycheck.xml + fi + mv sanity-out/sanitycheck.xml sanitycheck-${BUILDKITE_JOB_ID}.xml + buildkite-agent artifact upload sanitycheck-${BUILDKITE_JOB_ID}.xml + + + # Upload test_file to get list of tests that are build/run + if [ -f test_file.txt ]; then + buildkite-agent artifact upload test_file.txt + fi + + # ccache stats + echo "--- ccache stats at finish" + ccache -s + + # disk usage + echo "--- disk usage at finish" + df -h +} + +trap cleanup ERR echo "--- run $0" @@ -46,24 +73,6 @@ fi SANITY_EXIT_STATUS=$? -# Rename sanitycheck junit xml for use with junit-annotate-buildkite-plugin -# create dummy file if sanitycheck did nothing -if [ ! -f sanity-out/sanitycheck.xml ]; then - touch sanity-out/sanitycheck.xml -fi -mv sanity-out/sanitycheck.xml sanitycheck-${BUILDKITE_JOB_ID}.xml -buildkite-agent artifact upload sanitycheck-${BUILDKITE_JOB_ID}.xml - - -# Upload test_file to get list of tests that are build/run -buildkite-agent artifact upload test_file.txt - -# ccache stats -echo "--- ccache stats at finish" -ccache -s - -# disk usage -echo "--- disk usage at finish" -df -h +cleanup exit ${SANITY_EXIT_STATUS}