woodpecker-xmpp/entrypoint.sh

50 lines
1.4 KiB
Bash
Raw Normal View History

2023-08-18 21:04:55 +00:00
#!/bin/bash
2023-08-19 15:11:29 +00:00
# Allow debugging
[[ -n "${PLUGIN_DEBUG}" ]] && set -x
# Set the correct message
2023-08-19 10:59:33 +00:00
if [[ "${CI_BUILD_STATUS}" = "success" ]]; then
2023-08-19 15:11:29 +00:00
MESSAGE="✔️ Pipeline for ${CI_COMMIT_SHA} on ${CI_REPO} succeeded."
2023-08-18 21:04:55 +00:00
else
2023-08-19 15:11:29 +00:00
MESSAGE="❌ Pipeline for ${CI_COMMIT_SHA} on ${CI_REPO} failed on ${CI_MACHINE} (${CI_SYSTEM_ARCH}).\nSee ${CI_BUILD_LINK}"
2023-08-18 21:04:55 +00:00
fi
2023-08-19 15:11:29 +00:00
# Tell go-sendxmpp about the server to connect to, if specified
2023-08-18 21:04:55 +00:00
SERVER_DETAILS=""
2023-08-19 15:11:29 +00:00
if [[ -n "${XMPP_SERVER}" ]]; then
2023-08-19 11:03:42 +00:00
SERVER_DETAILS=(-j "${XMPP_SERVER}")
2023-08-18 21:04:55 +00:00
fi
2023-08-19 15:11:29 +00:00
# Force TLS, if configured
2023-08-18 21:04:55 +00:00
SERVER_TLS=""
2023-08-19 15:11:29 +00:00
if [[ -n "${PLUGIN_XMPP_TLS}" ]]; then
2023-08-18 21:04:55 +00:00
SERVER_TLS=--tls
fi
2023-08-19 15:11:29 +00:00
# Enable groupchat settings, if configured.
GROUPCHAT=""
2023-08-19 15:11:29 +00:00
if [[ -n "${PLUGIN_XMPP_IS_MUC}" ]]; then
GROUPCHAT="-c"
# Make the bot nickname configurable
2023-08-19 15:11:29 +00:00
BOT_ALIAS=(-a "${PLUGIN_XMPP_ALIAS:-"Woodpecker CI"}")
fi
# Sanity checks
CANCEL=""
if [[ -z "${XMPP_JID}" ]]; then
echo "Error: No JID specified using XMPP_JID"
CANCEL="y"
fi
if [[ -z "${XMPP_PASSWORD}" ]]; then
echo "Error: No password specified using XMPP_PASSWORD"
CANCEL="y"
fi
[[ -n "${CANCEL}" ]] && exit 1
2023-08-19 15:11:29 +00:00
# "Post" the message
# Disable SC2086 (double quote to prevent word splitting) and SC2068 (double quote array expansion to prevent word splitting)
# because we DO want word splitting here.
# shellcheck disable=SC2086,SC2068
echo -e "$MESSAGE" | go-sendxmpp -u ${XMPP_JID} -p ${XMPP_PASSWORD} ${SERVER_DETAILS[@]} ${SERVER_TLS} ${BOT_ALIAS[@]} ${GROUPCHAT} ${PLUGIN_XMPP_RECIPIENT}