53 lines
1.1 KiB
Bash
53 lines
1.1 KiB
Bash
|
#!/bin/sh
|
||
|
|
||
|
DEFAULT_TAGS="drone,$CI_REPO_NAME/$CI_COMMIT_BRANCH"
|
||
|
BASE_URL=${PLUGIN_URL:-"https://ntfy.sh"}
|
||
|
TOPIC=$PLUGIN_TOPIC # mandatory
|
||
|
TITLE="Build #$DRONE_BUILD_NUMBER $DRONE_BUILD_STATUS"
|
||
|
PRIORITY=${PLUGIN_PRIORITY:-""}
|
||
|
TAGS=${PLUGIN_TAGS:-""}
|
||
|
|
||
|
MESSAGE="[${CI_COMMIT_SHA:0:8}] $CI_COMMIT_MESSAGE"
|
||
|
|
||
|
if [ -z "$TOPIC" ]
|
||
|
then
|
||
|
echo "Topic cannot be empty.";
|
||
|
exit 1
|
||
|
fi
|
||
|
|
||
|
URL="$BASE_URL/$TOPIC"
|
||
|
|
||
|
if [ $DRONE_BUILD_STATUS = "success" ]
|
||
|
then
|
||
|
DEFAULT_TAGS="$DEFAULT_TAGS,white_check_mark"
|
||
|
elif [ $DRONE_BUILD_STATUS = "failure" ]
|
||
|
then
|
||
|
DEFAULT_TAGS="$DEFAULT_TAGS,x"
|
||
|
else
|
||
|
DEFAULT_TAGS="$DEFAULT_TAGS,grey_question"
|
||
|
fi
|
||
|
|
||
|
TAGS="$DEFAULT_TAGS,$TAGS"
|
||
|
TAGS=${TAGS%,}
|
||
|
|
||
|
HTTP_STATUS=$(
|
||
|
curl \
|
||
|
-o /dev/null -s -w "%{http_code}\n" \
|
||
|
--retry 3 --retry-delay 5 \
|
||
|
-u $PLUGIN_USERNAME:$PLUGIN_PASSWORD \
|
||
|
-H title:"$TITLE" \
|
||
|
-H tags:$TAGS \
|
||
|
-H prio:$PRIORITY \
|
||
|
-H "Actions: view, Build, $DRONE_BUILD_LINK; view, Changes, $DRONE_COMMIT_LINK" \
|
||
|
-d "$MESSAGE" \
|
||
|
$URL
|
||
|
)
|
||
|
|
||
|
if [ $? -eq 0 ] && [ $HTTP_STATUS -eq 200 ]
|
||
|
then
|
||
|
echo "Message sent!"
|
||
|
else
|
||
|
echo "Error publishing notification."
|
||
|
exit 2
|
||
|
fi
|