On Tue, Jan 12, 2021 at 03:42:52PM +0800, Wei Jihui wrote:
It is convenient for other tasks reuse to send email [usage] job.yaml test_task: on_fail: send_email: job_failed sleep: 1h
This will send email to user when job is failed.
Signed-off-by: Wei Jihui weijihuiall@163.com
lib/email.sh | 26 ++++++++++++++++++++++++++ tests/email | 41 ----------------------------------------- tests/send_email | 21 +++++++++++++++++++++ 3 files changed, 47 insertions(+), 41 deletions(-) create mode 100755 lib/email.sh delete mode 100755 tests/email create mode 100755 tests/send_email
diff --git a/lib/email.sh b/lib/email.sh new file mode 100755 index 00000000..a407ad40 --- /dev/null +++ b/lib/email.sh @@ -0,0 +1,26 @@ +#!/bin/sh
+job_failed_content() +{
- email_content="To: $my_email
+Subject: [NOTIFY Compass-CI] Test job failed: $id
+Dear $my_name:
- Sorry to inform you that your test job is failed. you can click the following link to view details.
- http://api.compass-ci.openeuler.org:$%7BSRV_HTTP_PORT:-11300%7D$result_root
+Regards +Compass-CI +" +}
+send_email() +{
- local subject=$1
- local email_content
- ${subject}_content
- curl -XPOST "${MAIL_HOST:-$LKP_SERVER}:${MAIL_PORT:-49000}/send_mail_text" -d "$email_content"
+} diff --git a/tests/email b/tests/email deleted file mode 100755 index a5f87d42..00000000 --- a/tests/email +++ /dev/null @@ -1,41 +0,0 @@ -#!/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.
- http://api.compass-ci.openeuler.org:$SRV_HTTP_PORT/$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 diff --git a/tests/send_email b/tests/send_email new file mode 100755 index 00000000..2911d3b8 --- /dev/null +++ b/tests/send_email @@ -0,0 +1,21 @@ +#!/bin/sh +# - subject +# my_email
+SCRIPT_DIR=$(dirname $(realpath $0)) +PROJECT_DIR=$(dirname $SCRIPT_DIR)
+. $PROJECT_DIR/lib/email.sh
+[ -n "$my_email" ] || {
- echo "Can not get my_email, send email failed!"
- exit 0
+}
+[ -n "$subject" ] || {
- echo "Can not get email subject, send email failed!"
- exit 0
+}
+send_email $subject
Maybe you should add double quotation marks, if the subject="aa bb cc", your $1=aa.
Thanks, Baijing
-- 2.23.0