Remove depricated flags and add fix missing
[releng/builder.git] / jjb / autorelease / include-raw-autorelease-notify-build-failure.sh
1 #!/bin/bash -x
2 # @License EPL-1.0 <http://spdx.org/licenses/EPL-1.0>
3 ##############################################################################
4 # Copyright (c) 2017 The Linux Foundation and others.
5 #
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Eclipse Public License v1.0
8 # which accompanies this distribution, and is available at
9 # http://www.eclipse.org/legal/epl-v10.html
10 ##############################################################################
11
12 RELEASE_EMAIL="release@lists.opendaylight.org"
13 ARCHIVES_DIR="$JENKINS_HOSTNAME/$JOB_NAME/$BUILD_NUMBER"
14 CONSOLE_LOG="/tmp/autorelease-build.log"
15 STREAM=${JOB_NAME#*-*e-}
16
17 # get console logs
18 wget -O "$CONSOLE_LOG" "${BUILD_URL}consoleText"
19
20 # extract the failing project or artifactid
21 REACTOR_INFO=$(awk '/Reactor Summary:/ { flag=1 }
22           flag {
23              if ( sub(/^\[(INFO)\]/,"") && sub(/FAILURE \[.*/,"") ) {
24                  gsub(/[[:space:]]*::[[:space:]]*/,"::")
25                  gsub(/^[[:space:]]+|[[:space:]]+$|[.]/,"")
26                  print
27              }
28           }
29           /Final Memory:/ { flag=0 }' $CONSOLE_LOG)
30
31 # check for project format
32 if [[ ${REACTOR_INFO} =~ .*::*.*::*. ]]; then
33     # extract project and artifactid from full format
34     ODL=$(echo "${REACTOR_INFO}" | awk -F'::' '{ gsub(/^[ \t]+|[ \t]+$/, "", $1); print $1 }')
35     PROJECT=$(echo "${REACTOR_INFO}" | awk -F'::' '{ gsub(/^[ \t]+|[ \t]+$/, "", $2); print $2 }')
36     ARTIFACTID=$(echo "${REACTOR_INFO}" | awk -F'::' '{ gsub(/^[ \t]+|[ \t]+$/, "", $3); print $3 }')
37 else
38     # set ARTIFACTID to partial format
39     ODL=""
40     PROJECT=""
41     ARTIFACTID=$(echo "${REACTOR_INFO}" | awk '{ gsub(/^[ \t]+|[ \t]+$/, ""); print }')
42 fi
43
44 # Construct email subject & body
45 PROJECT_STRING=${PROJECT:+" from $PROJECT"}
46 SUBJECT="[release] Autorelease $STREAM failed to build $ARTIFACTID$PROJECT_STRING"
47 BODY="Attention ${PROJECT:-"OpenDaylight"}-devs,
48
49 Autorelease $STREAM failed to build $ARTIFACTID$PROJECT_STRING in build
50 $BUILD_NUMBER. Attached is a snippet of the error message related to the
51 failure that we were able to automatically parse as well as console logs.
52
53 Console Logs:
54 https://logs.opendaylight.org/$SILO/$ARCHIVES_DIR
55
56 Jenkins Build:
57 $BUILD_URL
58
59 Please review and provide an ETA on when a fix will be available.
60
61 Thanks,
62 ODL releng/autorelease team
63 "
64
65 # check if remote staging is complete successfully
66 BUILD_STATUS=$(awk '/\[INFO\] Remote staging finished/{flag=1;next}/Total time:/{flag=0}flag' $CONSOLE_LOG \
67                    | grep '\] BUILD' | awk '{print $3}')
68
69 if [ ! -z "${ARTIFACTID}" ] && [[ "${BUILD_STATUS}" != "SUCCESS" ]]; then
70     # project search pattern should handle both scenarios
71     # 1. Full format:    ODL :: $PROJECT :: $ARTIFACTID
72     # 2. Partial format: Building $ARTIFACTID
73     sed -e "/\[INFO\] Building \(${ARTIFACTID} \|${ODL} :: ${PROJECT} :: ${ARTIFACTID} \)/,/Reactor Summary:/!d;//d" \
74           $CONSOLE_LOG > /tmp/error.txt
75
76     if [ -n "${PROJECT}" ]; then
77         RELEASE_EMAIL="${RELEASE_EMAIL}, ${PROJECT}-dev@lists.opendaylight.org"
78     fi
79
80     # Only send emails in production (releng), not testing (sandbox)
81     if [ "${SILO}" == "releng" ]; then
82         echo "${BODY}" | mail -a /tmp/error.txt \
83             -r "Jenkins <jenkins-dontreply@opendaylight.org>" \
84             -s "${SUBJECT}" "${RELEASE_EMAIL}"
85     elif [ "${SILO}" == "sandbox" ]; then
86         echo "Running in sandbox, not actually sending notification emails"
87         echo "Subject: ${SUBJECT}"
88         echo "Body: ${BODY}"
89     else
90         echo "Not sure how to notify in \"${SILO}\" Jenkins silo"
91     fi
92 fi
93
94 rm $CONSOLE_LOG