Create simple script to notify via Ntfy
This commit is contained in:
parent
4b6c2b5973
commit
28011b3fe3
3 changed files with 107 additions and 36 deletions
65
.drone.yml
65
.drone.yml
|
@ -12,6 +12,7 @@ steps:
|
||||||
settings:
|
settings:
|
||||||
repo: parrazam/drone-ntfy
|
repo: parrazam/drone-ntfy
|
||||||
auto_tag: true
|
auto_tag: true
|
||||||
|
auto_tag_suffix: linux-amd64
|
||||||
mirror: https://registry.cuzo.dev
|
mirror: https://registry.cuzo.dev
|
||||||
username:
|
username:
|
||||||
from_secret: docker_hub_user
|
from_secret: docker_hub_user
|
||||||
|
@ -42,12 +43,31 @@ steps:
|
||||||
path: docker
|
path: docker
|
||||||
settings:
|
settings:
|
||||||
target: parrazam/drone-ntfy
|
target: parrazam/drone-ntfy
|
||||||
|
template: parrazam/drone-ntfy:OS-ARCH
|
||||||
auto_tag: true
|
auto_tag: true
|
||||||
ignore_missing: true
|
ignore_missing: true
|
||||||
username:
|
username:
|
||||||
from_secret: docker_hub_user
|
from_secret: docker_hub_user
|
||||||
password:
|
password:
|
||||||
from_secret: docker_hub_pass
|
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:
|
depends_on:
|
||||||
- build
|
- build
|
||||||
|
@ -74,9 +94,19 @@ steps:
|
||||||
api_key:
|
api_key:
|
||||||
from_secret: drone_api_key
|
from_secret: drone_api_key
|
||||||
base_url: https://git.parravidales.es
|
base_url: https://git.parravidales.es
|
||||||
|
- name: send ntfy notification
|
||||||
|
image: registry.cuzo.dev/parrazam/drone-ntfy
|
||||||
when:
|
when:
|
||||||
ref:
|
status: [success, failure]
|
||||||
- refs/tags/*
|
settings:
|
||||||
|
url: https://ntfy.parravidales.es
|
||||||
|
topic: pipelines
|
||||||
|
priority: low
|
||||||
|
tags: release
|
||||||
|
username:
|
||||||
|
from_secret: ntfy_user
|
||||||
|
password:
|
||||||
|
from_secret: ntfy_password
|
||||||
|
|
||||||
depends_on:
|
depends_on:
|
||||||
- manifest
|
- manifest
|
||||||
|
@ -87,34 +117,3 @@ image_pull_secrets:
|
||||||
trigger:
|
trigger:
|
||||||
event:
|
event:
|
||||||
- tag
|
- 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
56
README.md
Normal 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*
|
22
script.sh
22
script.sh
|
@ -1,14 +1,22 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
DEFAULT_TAGS="drone,$CI_REPO_NAME/$CI_COMMIT_BRANCH"
|
DEFAULT_TAGS="drone"
|
||||||
BASE_URL=${PLUGIN_URL:-"https://ntfy.sh"}
|
BASE_URL=${PLUGIN_URL:-"https://ntfy.sh"}
|
||||||
TOPIC=$PLUGIN_TOPIC # mandatory
|
TOPIC=$PLUGIN_TOPIC # mandatory
|
||||||
TITLE="Build #$DRONE_BUILD_NUMBER $DRONE_BUILD_STATUS"
|
TITLE="Build #$DRONE_BUILD_NUMBER $DRONE_BUILD_STATUS"
|
||||||
PRIORITY=${PLUGIN_PRIORITY:-""}
|
PRIORITY=${PLUGIN_PRIORITY:-"default"}
|
||||||
TAGS=${PLUGIN_TAGS:-""}
|
TAGS=${PLUGIN_TAGS:-""}
|
||||||
|
|
||||||
MESSAGE="[${CI_COMMIT_SHA:0:8}] $CI_COMMIT_MESSAGE"
|
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" ]
|
if [ -z "$TOPIC" ]
|
||||||
then
|
then
|
||||||
echo "Topic cannot be empty.";
|
echo "Topic cannot be empty.";
|
||||||
|
@ -30,11 +38,19 @@ fi
|
||||||
TAGS="$DEFAULT_TAGS,$TAGS"
|
TAGS="$DEFAULT_TAGS,$TAGS"
|
||||||
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=$(
|
HTTP_STATUS=$(
|
||||||
curl \
|
curl \
|
||||||
-o /dev/null -s -w "%{http_code}\n" \
|
-o /dev/null -s -w "%{http_code}\n" \
|
||||||
--retry 3 --retry-delay 5 \
|
--retry 3 --retry-delay 5 \
|
||||||
-u $PLUGIN_USERNAME:$PLUGIN_PASSWORD \
|
$AUTH_HEADER \
|
||||||
-H title:"$TITLE" \
|
-H title:"$TITLE" \
|
||||||
-H tags:$TAGS \
|
-H tags:$TAGS \
|
||||||
-H prio:$PRIORITY \
|
-H prio:$PRIORITY \
|
||||||
|
|
Loading…
Reference in a new issue