Create simple script to notify via Ntfy
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/tag Build is passing Details

This commit is contained in:
parra 2023-02-09 17:11:55 +01:00
parent 4b6c2b5973
commit 28011b3fe3
3 changed files with 107 additions and 36 deletions

View File

@ -12,6 +12,7 @@ steps:
settings:
repo: parrazam/drone-ntfy
auto_tag: true
auto_tag_suffix: linux-amd64
mirror: https://registry.cuzo.dev
username:
from_secret: docker_hub_user
@ -42,12 +43,31 @@ steps:
path: docker
settings:
target: parrazam/drone-ntfy
template: parrazam/drone-ntfy:OS-ARCH
auto_tag: true
ignore_missing: true
username:
from_secret: docker_hub_user
password:
from_secret: docker_hub_pass
platforms:
- linux/amd64
- name: send ntfy notification
image: registry.cuzo.dev/parrazam/drone-ntfy
when:
status: [success, failure]
ref:
exclude:
- refs/tags/*
settings:
url: https://ntfy.parravidales.es
topic: pipelines
priority: low
tags: manifest
username:
from_secret: ntfy_user
password:
from_secret: ntfy_password
depends_on:
- build
@ -74,9 +94,19 @@ steps:
api_key:
from_secret: drone_api_key
base_url: https://git.parravidales.es
- name: send ntfy notification
image: registry.cuzo.dev/parrazam/drone-ntfy
when:
ref:
- refs/tags/*
status: [success, failure]
settings:
url: https://ntfy.parravidales.es
topic: pipelines
priority: low
tags: release
username:
from_secret: ntfy_user
password:
from_secret: ntfy_password
depends_on:
- manifest
@ -87,34 +117,3 @@ image_pull_secrets:
trigger:
event:
- tag
---
kind: pipeline
type: docker
name: Notify result
steps:
- name: send ntfy notification
image: registry.cuzo.dev/parrazam/drone-ntfy
settings:
url: https://ntfy.parravidales.es
topic: pipelines
priority: low
username:
from_secret: ntfy_user
password:
from_secret: ntfy_password
depends_on:
- manifest
- release
image_pull_secrets:
- custom_mirror_registry
trigger:
event:
- push
- tag
exclude:
- pull_request

56
README.md Normal file
View File

@ -0,0 +1,56 @@
# Drone Ntfy plugin
[![Build Status](https://ci.cuzo.dev/api/badges/parra/drone-ntfy/status.svg)](https://ci.cuzo.dev/parra/drone-ntfy)
The Ntfy.sh plugin posts build status messages to your selected Ntfy server.
Example:
```yml
kind: pipeline
name: default
steps:
- name: send ntfy notification
image: parrazam/drone-ntfy
when:
status: [success, failure]
settings:
url: https://ntfy.example.org
topic: events
priority: low
tags:
- pipeline-status
- dev
username:
from_secret: ntfy_user
password:
from_secret: ntfy_password
```
## Properties
`url` *string* [optional] \
Ntfy server.
> *Default: https://ntfy.sh*
`topic` *string* [**REQUIRED**] \
Topic to publish message.
> *Default: none*
`priority` *string* [optional] \
Priority of the notification. Values can be [min, low, default, high, max].
> *Default: default*
`tags` *string* [optional] \
Custom tags to include.
> *Default: none*
`username` *string* [optional] \
Username with publish permissions.
> *Default: none*
`password` *string* [optional] \
[***SECRET RECOMMENDED***] \
Password for username.
> *Default: none*

View File

@ -1,14 +1,22 @@
#!/bin/sh
DEFAULT_TAGS="drone,$CI_REPO_NAME/$CI_COMMIT_BRANCH"
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:-""}
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.";
@ -30,11 +38,19 @@ 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 \
-u $PLUGIN_USERNAME:$PLUGIN_PASSWORD \
$AUTH_HEADER \
-H title:"$TITLE" \
-H tags:$TAGS \
-H prio:$PRIORITY \