tests/rpmbuild-pkg: add a new input parameter whether_email [usage]: rpmbuild-pkg: whether_email: 1
when job failed, send an rpmbuild failed email. when job run success, send an rpmbuild success email.
Signed-off-by: Li Ping 1477412247@qq.com --- lib/email.sh | 35 +++++++++++++++++++++++++++++++++++ tests/rpmbuild-pkg | 24 ++++++++++++++++++++++++ 2 files changed, 59 insertions(+)
diff --git a/lib/email.sh b/lib/email.sh index b5e56df79..a6e0bc3ba 100755 --- a/lib/email.sh +++ b/lib/email.sh @@ -96,6 +96,41 @@ Compass-CI " }
+rpmbuild_report() +{ + email_content="To: $author_email +Subject: [NOTIFY Compass-CI] rpmbuild report + +Dear $author_name: + + $rpmbuild_result + +Regards +Compass-CI +" +} + +rpmbuild_success_content() +{ + rpmbuild_result="Your RPM Package is successfully built. + +You can click the follow link to obtain your RPM Package: +http://api.compass-ci.openeuler.org:20012/rpm/pub/$%7Bos%7D-$%7Bos_version%7... + +And you can click the following link to view RPM Package build details: +http://api.compass-ci.openeuler.org:$%7BSRV_HTTP_RESULT_PORT:-20007%7D$resul..." + + rpmbuild_report +} + +rpmbuild_failed_content() +{ + rpmbuild_result="Sorry to inform you that RPM Package built failed, you can click the following link to view details. +http://api.compass-ci.openeuler.org:$%7BSRV_HTTP_RESULT_PORT:-20007%7D$resul..." + + rpmbuild_report +} + send_email() { local subject=$1 diff --git a/tests/rpmbuild-pkg b/tests/rpmbuild-pkg index 3dd75b896..5ad5caf56 100755 --- a/tests/rpmbuild-pkg +++ b/tests/rpmbuild-pkg @@ -5,6 +5,7 @@ # - repo_addr # - custom_repo_name # - custom_repo_addr +# - whether_email # Git repo jobs only use the first two parameters, SRPMs jobs use all # user can add custom_repo_name and custom_repo_addr to setup # local repo, value can be an array @@ -12,6 +13,7 @@ . $LKP_SRC/lib/debug.sh . $LKP_SRC/lib/upload.sh . $LKP_SRC/lib/rpm.sh +. $LKP_SRC/lib/email.sh
: "${compat_os:=budding-openeuler}"
@@ -19,6 +21,13 @@
dest_dir="/rpm/upload/${os}-${os_version}/${compat_os}"
+die() +{ + rpmbuild_email "rpmbuild_failed" + echo "$@" 1>&2 + exit 99 +} + from_git() { package_name=${upstream_repo##*/} @@ -29,6 +38,20 @@ from_git() download_upstream_repo }
+git_pretty_format() +{ + curl -sS -H 'Content-Type: Application/json' -XPOST "$LKP_SERVER"':8100/git_command' -d '{"git_repo": "'${upstream_dir}/${upstream_repo}.git'", "git_command": ["git-log","-n1","--pretty=format:'$1'", "'${upstream_commit}'"]}' +} + +rpmbuild_email() +{ + [ -n "$whether_email" ] && { + author_email=$(git_pretty_format "%ae") + author_name=$(git_pretty_format "%an") + send_email $1 + } +} + from_srpm() { [ -n "$repo_name" ] || die "repo_name is empty" @@ -143,3 +166,4 @@ add_repo build_rpm upload_rpm_pkg update_repo_mq +rpmbuild_email "rpmbuild_success"