Enable mailing list for notify script
[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 BODY="Please refer to the logs server URL for console logs when possible
18 and use the Jenkins Build URL as a last resort.
19
20 Console Logs URL:
21 https://logs.opendaylight.org/$SILO/$ARCHIVES_DIR
22
23 Jenkins Build URL:
24 $BUILD_URL"
25
26 # get console logs
27 wget -O $CONSOLE_LOG ${BUILD_URL}consoleText
28
29 # extract the failing project or artifactid
30 REACTOR_INFO=`awk '/Reactor Summary:/ { flag=1 }
31           flag {
32              if ( sub(/^\[(INFO)\]/,"") && sub(/FAILURE \[.*/,"") ) {
33                  gsub(/[[:space:]]*::[[:space:]]*/,"::")
34                  gsub(/^[[:space:]]+|[[:space:]]+$|[.]/,"")
35                  print
36              }
37           }
38           /Final Memory:/ { flag=0 }' $CONSOLE_LOG`
39
40 # check for project format
41 if [[ ${REACTOR_INFO} =~ .*::*.*::*. ]]; then
42     # extract project and artifactid from full format
43     ODL=`echo ${REACTOR_INFO} | awk -F'::' '{ gsub(/^[ \t]+|[ \t]+$/, "", $1); print $1 }'`
44     PROJECT=`echo ${REACTOR_INFO} | awk -F'::' '{ gsub(/^[ \t]+|[ \t]+$/, "", $2); print $2 }'`
45     ARTIFACTID=`echo ${REACTOR_INFO} | awk -F'::' '{ gsub(/^[ \t]+|[ \t]+$/, "", $3); print $3 }'`
46 else
47     # set ARTIFACTID to partial format
48     ODL=""
49     PROJECT=""
50     ARTIFACTID=`echo ${REACTOR_INFO} | awk '{ gsub(/^[ \t]+|[ \t]+$/, ""); print }'`
51 fi
52
53 # check if remote staging is complete successfully
54 BUILD_STATUS=`awk '/\[INFO\] Remote staging finished/{flag=1;next} \
55                    /Total time:/{flag=0}flag' $CONSOLE_LOG \
56                    | grep '\] BUILD' | awk '{print $3}'`
57
58 if [ ! -z "${ARTIFACTID}" ] && [[ "${BUILD_STATUS}" != "SUCCESS" ]]; then
59     # project search pattern should handle both scenarios
60     # 1. Full format:    ODL :: $PROJECT :: $ARTIFACTID
61     # 2. Partial format: Building $ARTIFACTID
62     sed -e "/\[INFO\] Building \(${ARTIFACTID} \|${ODL} :: ${PROJECT} :: ${ARTIFACTID} \)/,/Reactor Summary:/!d;//d" \
63           $CONSOLE_LOG > /tmp/error_msg
64
65     if [ -z "${PROJECT}" ]; then
66         PROJECT=${ARTIFACTID}
67     else
68         RELEASE_EMAIL="${RELEASE_EMAIL}, ${PROJECT}-dev@opendaylight.org"
69     fi
70
71     SUBJECT="[release] Autorelease ${STREAM} build failure: ${PROJECT}"
72
73     echo "${BODY}" | mail -a /tmp/error_msg -s "${SUBJECT}" "${RELEASE_EMAIL}"
74 fi
75
76 rm $CONSOLE_LOG