send email to user when test job failed
Signed-off-by: Wei Jihui weijihuiall@163.com --- tests/email | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100755 tests/email
diff --git a/tests/email b/tests/email new file mode 100755 index 00000000..fe870471 --- /dev/null +++ b/tests/email @@ -0,0 +1,41 @@ +#!/bin/sh +# - my_email +# - info + +: ${info:=failure} + +SCRIPT_DIR=$(dirname $(realpath $0)) +PROJECT_DIR=$(dirname $SCRIPT_DIR) + +. $PROJECT_DIR/lib/http.sh +. $PROJECT_DIR/lib/env.sh + +data_failure() +{ + data="To: $my_email +Subject: [NOTIFY Compass-ci] Test job failed + +Dear $my_username: + + Sorry to inform you that your test job is failed. you can click the following link to view details. + https://compass-ci.openeuler.org/$result_root + +Regards +Compass-Ci +" +} + +compose_email() +{ + [ "$info" == "failure" ] && data_failure +} + +run_email() +{ + [ -n "$my_email" ] || return 0 + my_username=$(echo "$my_email" | awk -F '@' '{print $1}') + compose_email + curl -XPOST "${MAIL_HOST:-$LKP_SERVER}:${MAIL_PORT:-49000}/send_mail_text" -d "$data" +} + +run_email