2017-01-04 01:01:43 +03:00
|
|
|
#!/bin/bash
|
|
|
|
set -eo pipefail
|
|
|
|
|
2017-01-10 23:38:55 +03:00
|
|
|
# Required environment variables if using --stage:
|
2017-02-07 20:06:38 +03:00
|
|
|
# BRANCH_NAME, BUILD_NUMBER
|
2017-01-04 01:01:43 +03:00
|
|
|
|
|
|
|
# defaults and constants
|
2017-01-10 23:38:55 +03:00
|
|
|
NICK="hms-flintstone"
|
2017-01-04 01:01:43 +03:00
|
|
|
CHANNEL="#www"
|
|
|
|
SERVER="irc.mozilla.org:6697"
|
2017-05-04 21:23:54 +03:00
|
|
|
BLUE_BUILD_URL="https://ci.us-west.moz.works/blue/organizations/jenkins/bedrock_multibranch_pipeline"
|
|
|
|
BLUE_BUILD_URL="${BLUE_BUILD_URL}/detail/${BRANCH_NAME/\//%2f}/${BUILD_NUMBER}/pipeline"
|
2017-01-04 01:01:43 +03:00
|
|
|
# colors and styles: values from the following links
|
|
|
|
# http://www.mirc.com/colors.html
|
|
|
|
# http://stackoverflow.com/a/13382032
|
|
|
|
RED=$'\x034'
|
2017-01-10 23:38:55 +03:00
|
|
|
YELLOW=$'\x038'
|
2017-01-04 01:01:43 +03:00
|
|
|
GREEN=$'\x039'
|
|
|
|
BLUE=$'\x0311'
|
|
|
|
BOLD=$'\x02'
|
|
|
|
NORMAL=$'\x0F'
|
|
|
|
|
|
|
|
# parse cli args
|
|
|
|
while [[ $# -gt 1 ]]; do
|
|
|
|
key="$1"
|
|
|
|
case $key in
|
|
|
|
--stage)
|
|
|
|
STAGE="$2"
|
|
|
|
shift # past argument
|
|
|
|
;;
|
|
|
|
--status)
|
|
|
|
STATUS="$2"
|
|
|
|
shift # past argument
|
|
|
|
;;
|
|
|
|
-m|--message)
|
|
|
|
MESSAGE="$2"
|
|
|
|
shift # past argument
|
|
|
|
;;
|
|
|
|
--irc_nick)
|
|
|
|
NICK="$2"
|
|
|
|
shift # past argument
|
|
|
|
;;
|
|
|
|
--irc_server)
|
|
|
|
SERVER="$2"
|
|
|
|
shift # past argument
|
|
|
|
;;
|
|
|
|
--irc_channel)
|
|
|
|
CHANNEL="$2"
|
|
|
|
shift # past argument
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
shift # past argument or value
|
|
|
|
done
|
|
|
|
|
2017-01-10 23:38:55 +03:00
|
|
|
if [[ -n "$STATUS" ]]; then
|
|
|
|
STATUS=$(echo "$STATUS" | tr '[:lower:]' '[:upper:]')
|
|
|
|
case "$STATUS" in
|
|
|
|
'SUCCESS')
|
|
|
|
STATUS_COLOR="🎉 ${BOLD}${GREEN}"
|
|
|
|
;;
|
|
|
|
'SHIPPED')
|
|
|
|
STATUS_COLOR="🚢 ${BOLD}${GREEN}"
|
|
|
|
;;
|
|
|
|
'WARNING')
|
|
|
|
STATUS_COLOR="⚠️ ${BOLD}${YELLOW}"
|
|
|
|
;;
|
|
|
|
'FAILURE')
|
|
|
|
STATUS_COLOR="🚨 ${BOLD}${RED}"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
STATUS_COLOR="✨ $BLUE"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
STATUS="${STATUS_COLOR}${STATUS}${NORMAL}: "
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -n "$STAGE" ]]; then
|
|
|
|
MESSAGE="${STATUS}${STAGE}:"
|
2017-02-07 20:06:38 +03:00
|
|
|
MESSAGE="$MESSAGE Branch ${BOLD}${BRANCH_NAME}${NORMAL} build #${BUILD_NUMBER}: ${BLUE_BUILD_URL}"
|
2017-01-10 23:38:55 +03:00
|
|
|
elif [[ -n "$MESSAGE" ]]; then
|
|
|
|
MESSAGE="${STATUS}${MESSAGE}"
|
|
|
|
else
|
|
|
|
echo "Missing required arguments"
|
|
|
|
echo
|
|
|
|
echo "Usage: irc-notify.sh [--stage STAGE]|[-m MESSAGE]"
|
|
|
|
echo "Optional args: --status, --irc_nick, --irc_server, --irc_channel"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -n "$BUILD_NUMBER" ]]; then
|
|
|
|
NICK="${NICK}-${BUILD_NUMBER}"
|
2017-01-04 01:01:43 +03:00
|
|
|
fi
|
|
|
|
|
|
|
|
(
|
|
|
|
echo "NICK ${NICK}"
|
|
|
|
echo "USER ${NICK} 8 * : ${NICK}"
|
|
|
|
sleep 5
|
|
|
|
echo "JOIN ${CHANNEL}"
|
|
|
|
echo "NOTICE ${CHANNEL} :${MESSAGE}"
|
|
|
|
echo "QUIT"
|
|
|
|
) | openssl s_client -connect "$SERVER" > /dev/null 2>&1
|