Use eval command to append mail options 47/65947/1
authorAnil Belur <abelur@linuxfoundation.org>
Tue, 28 Nov 2017 00:45:29 +0000 (10:45 +1000)
committerAnil Belur <abelur@linuxfoundation.org>
Tue, 28 Nov 2017 01:14:41 +0000 (11:14 +1000)
Use eval to append mail options with the notify script. When the eval
command is used without escaping the variables causes wordsplitting.

Ref: http://mywiki.wooledge.org/BashFAQ/050

JIRA: RELENG-213
Change-Id: I736f3eaa98d58c4514a936c137d2a2df77053167
Signed-off-by: Anil Belur <abelur@linuxfoundation.org>
jjb/autorelease/notify-build-failure.sh

index 090e808039b1213b3c39127328813fc179737234..e17ce7f843dce3827ab81d3f66514b8352b26f13 100644 (file)
@@ -125,24 +125,24 @@ if ([ ! -z "${NAME}" ] || [ ! -z "${ARTIFACT_ID}" ]) && [[ "${BUILD_STATUS}" !=
           $CONSOLE_LOG | gzip > "$ERROR_LOG"
 
     if [ -n "${PROJECT}" ]; then
-        RELEASE_EMAIL="${RELEASE_EMAIL}, ${PROJECT}-dev@lists.opendaylight.org"
+        RELEASE_EMAIL="\${RELEASE_EMAIL}, \${PROJECT}-dev@lists.opendaylight.org"
     fi
 
     file_size=$(du -k "$ERROR_LOG" | cut -f1)
 
+    PARAMS=("-r \"Jenkins <jenkins-dontreply@opendaylight.org>\"")
+    PARAMS+=("-s \"$SUBJECT\"")
     # Only send emails in production (releng), not testing (sandbox)
     if [ "${SILO}" == "releng" ]; then
         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}"
+            PARAMS+=("-a \"$ERROR_LOG\"")
         fi
+
+        eval echo \""${BODY}"\" | eval mail "${PARAMS[*]}" "${RELEASE_EMAIL}"
+
     elif [ "${SILO}" == "sandbox" ]; then
         echo "Running in sandbox, not actually sending notification emails"
         echo "Subject: ${SUBJECT}"