Compress large error attachments 04/54204/12
authorAnil Belur <abelur@linuxfoundation.org>
Sun, 26 Mar 2017 00:21:50 +0000 (10:21 +1000)
committerAnil Belur <abelur@linuxfoundation.org>
Thu, 13 Apr 2017 12:35:23 +0000 (22:35 +1000)
- Verify file size does not exceed release mailing list attachment
  limit and exclude sending the attachment if the file exceeds limits
- Rename file (error.log) and create a compressed file under $WORKSPACE
  so that the file gets archived.
- Update email body with relevent information on the attachment, if
  its not included.

Jira: https://jira.linuxfoundation.org/browse/RELENG-6
Bug: https://bugs.opendaylight.org/show_bug.cgi?id=7977
Change-Id: Id2a6dc168bc0f1b5e6f07ea1ed1d25db7702b5e3
Signed-off-by: Anil Belur <abelur@linuxfoundation.org>
jjb/autorelease/include-raw-autorelease-notify-build-failure.sh

index e50ec453c0d791b3401413e8df4313ef900878e1..951d0075ca718ed1b2830416e872ae7f3c96e20b 100644 (file)
@@ -9,10 +9,12 @@
 # http://www.eclipse.org/legal/epl-v10.html
 ##############################################################################
 
+NEWLINE=$'\n'
 RELEASE_EMAIL="release@lists.opendaylight.org"
 ARCHIVES_DIR="$JENKINS_HOSTNAME/$JOB_NAME/$BUILD_NUMBER"
 CONSOLE_LOG="/tmp/autorelease-build.log"
 STREAM=${JOB_NAME#*-*e-}
+ERROR_LOG="$WORKSPACE/error.log.gz"
 
 # get console logs
 wget -O "$CONSOLE_LOG" "${BUILD_URL}consoleText"
@@ -37,13 +39,12 @@ if [[ ${REACTOR_INFO} =~ .*::*.*::*. ]]; then
     PROJECT_=$(echo "${REACTOR_INFO}" | awk -F'::' '{ gsub(/^[ \t]+|[ \t]+$/, "", $2); print $2 }')
     NAME=$(echo "${REACTOR_INFO}" | awk -F'::' '{ gsub(/^[ \t]+|[ \t]+$/, "", $3); print $3 }')
 else
-    # set ARTIFACTID to partial format
+    # set project from partial format
     ODL=""
     PROJECT_=""
     NAME=$(echo "${REACTOR_INFO}" | awk '{ gsub(/^[ \t]+|[ \t]+$/, ""); print }')
 fi
 
-
 # determine ARTIFACT_ID for project mailing list
 ARTIFACT_ID=$(awk -F: '/\[ERROR\].*mvn <goals> -rf :/ { print $2}' $CONSOLE_LOG)
 
@@ -86,12 +87,18 @@ fi
 # Construct email subject & body
 PROJECT_STRING=${PROJECT:+" from $PROJECT"}
 SUBJECT="[release] Autorelease $STREAM failed to build $ARTIFACT_ID$PROJECT_STRING"
+# shellcheck disable=SC2034
+ATTACHMENT_INCLUDE="Attached is a snippet of the error message related to the
+failure that we were able to automatically parse as well as console logs."
+# shellcheck disable=SC2034
+ATTACHMENT_EXCLUDE="Unable to attach error message snippet related to the failure
+since this exceeds the mail server attachment size limit. Please
+refer $ERROR_LOG in archives directory."
+ATTACHMENT=ATTACHMENT_INCLUDE  # default behaviour
 BODY="Attention ${PROJECT:-"OpenDaylight"}-devs,
 
 Autorelease $STREAM failed to build $ARTIFACT_ID$PROJECT_STRING in build
-$BUILD_NUMBER. Attached is a snippet of the error message related to the
-failure that we were able to automatically parse as well as console logs.
-${PROJECT:+"$GROUPLIST"}
+$BUILD_NUMBER. \${!ATTACHMENT} ${PROJECT:+${NEWLINE}${GROUPLIST}}
 
 Console Logs:
 https://logs.opendaylight.org/$SILO/$ARCHIVES_DIR
@@ -114,21 +121,31 @@ if ([ ! -z "${NAME}" ] || [ ! -z "${ARTIFACT_ID}" ]) && [[ "${BUILD_STATUS}" !=
     # 1. Full format:    ODL :: $PROJECT :: $ARTIFACT_ID
     # 2. Partial format: Building $ARTIFACT_ID
     sed -e "/\[INFO\] Building \(${NAME} \|${ARTIFACT_ID} \|${ODL} :: ${PROJECT_} :: ${NAME} \)/,/Reactor Summary:/!d;//d" \
-          $CONSOLE_LOG > /tmp/error.txt
+          $CONSOLE_LOG | gzip > "$ERROR_LOG"
 
     if [ -n "${PROJECT}" ]; then
         RELEASE_EMAIL="${RELEASE_EMAIL}, ${PROJECT}-dev@lists.opendaylight.org"
     fi
 
+    file_size=$(du -k "$ERROR_LOG" | cut -f1)
+
     # Only send emails in production (releng), not testing (sandbox)
     if [ "${SILO}" == "releng" ]; then
-        echo "${BODY}" | mail -a /tmp/error.txt \
-            -r "Jenkins <jenkins-dontreply@opendaylight.org>" \
-            -s "${SUBJECT}" "${RELEASE_EMAIL}"
+        if [[ "$file_size" -gt 100 ]]; then
+            # shellcheck disable=SC2034
+            ATTACHMENT=ATTACHMENT_EXCLUDE
+            eval echo \""${BODY}"\" | mail \
+                -r "Jenkins <jenkins-dontreply@opendaylight.org>" \
+                -s "${SUBJECT}" "${RELEASE_EMAIL}"
+        else
+            eval echo \""${BODY}"\" | mail -a "$ERROR_LOG" \
+                -r "Jenkins <jenkins-dontreply@opendaylight.org>" \
+                -s "${SUBJECT}" "${RELEASE_EMAIL}"
+        fi
     elif [ "${SILO}" == "sandbox" ]; then
         echo "Running in sandbox, not actually sending notification emails"
         echo "Subject: ${SUBJECT}"
-        echo "Body: ${BODY}"
+        eval echo \""Body: ${BODY}"\"
     else
         echo "Not sure how to notify in \"${SILO}\" Jenkins silo"
     fi