#!/bin/sh DEFAULT_TAGS="drone" BASE_URL=${PLUGIN_URL:-"https://ntfy.sh"} TOPIC=$PLUGIN_TOPIC # mandatory TITLE="Build #$DRONE_BUILD_NUMBER $DRONE_BUILD_STATUS" PRIORITY=${PLUGIN_PRIORITY:-"default"} TAGS=${PLUGIN_TAGS:-""} MESSAGE="[${CI_COMMIT_SHA:0:8}] $CI_COMMIT_MESSAGE" if [[ $CI_COMMIT_REF == *"refs/tags/"* ]] then MESSAGE="Tag $DRONE_TAG created" DEFAULT_TAGS="$DEFAULT_TAGS,$DRONE_TAG" else DEFAULT_TAGS="$DEFAULT_TAGS,$CI_REPO_NAME/$CI_COMMIT_BRANCH" fi 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%,} AUTH_HEADER="" if [ -z "$PLUGIN_USERNAME" ] || [ -z "$PLUGIN_PASSWORD" ] then echo "Trying to publish message in a public topic..." else AUTH_HEADER="-u $PLUGIN_USERNAME:$PLUGIN_PASSWORD" fi HTTP_STATUS=$( curl \ -o /dev/null -s -w "%{http_code}\n" \ --retry 3 --retry-delay 5 \ $AUTH_HEADER \ -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