First commit
Some checks reported errors
continuous-integration/drone/push Build encountered an error
Some checks reported errors
continuous-integration/drone/push Build encountered an error
This commit is contained in:
commit
245ec2d251
6 changed files with 135 additions and 0 deletions
17
.drone.yml
Normal file
17
.drone.yml
Normal file
|
@ -0,0 +1,17 @@
|
|||
kind: pipeline
|
||||
name: build
|
||||
type: docker
|
||||
|
||||
steps:
|
||||
- name: build
|
||||
image: plugins/docker
|
||||
settings:
|
||||
registry: r.regnault.dev
|
||||
username:
|
||||
from_secret: DOCKER_USERNAME
|
||||
password:
|
||||
from_secret: DOCKER_PASSWORD
|
||||
repo: r.regnault.dev/drone-discord-webhook
|
||||
dockerfile: docker/Dockerfile
|
||||
context: src/
|
||||
force_tag: true
|
29
README.md
Normal file
29
README.md
Normal file
|
@ -0,0 +1,29 @@
|
|||
# Drone Discord Webhook
|
||||
|
||||
This is a plugin for the [Drone CI/CD](https://www.drone.io/) tool which purpose is to post messages after each builds completed or failed.
|
||||
|
||||
## How to use it?
|
||||
|
||||
There are 3 environment variable that can be set.
|
||||
|
||||
(Required) `WEBHOOK_URL`: The url of the webhook that will send the status message
|
||||
|
||||
(Optionnal) `AVATAR`: Url of an image that'll be used for the webhook user.
|
||||
|
||||
(Optionnal) `USERNAME`: Username of the avatar that'll be assigned to the webhook.
|
||||
|
||||
```yaml
|
||||
- name: Send discord notification
|
||||
image: r.regnault.dev/drone-discord-webhook
|
||||
environment:
|
||||
AVATAR: "Optionnal webhook avatar url"
|
||||
USERNAME: "Optionnal webhook username"
|
||||
WEBHOOK_URL:
|
||||
from_secret: WEBHOOK_URL
|
||||
when:
|
||||
status: [ success, failure, changed ]
|
||||
```
|
||||
|
||||
## How does it look?
|
||||
|
||||

|
8
docker/Dockerfile
Normal file
8
docker/Dockerfile
Normal file
|
@ -0,0 +1,8 @@
|
|||
FROM alpine
|
||||
RUN apk add jq curl bash
|
||||
|
||||
COPY . /app
|
||||
WORKDIR /app
|
||||
RUN chmod +x launch.sh
|
||||
|
||||
ENTRYPOINT [ "/bin/bash", "/app/launch.sh" ]
|
BIN
images/image.png
Normal file
BIN
images/image.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 19 KiB |
37
src/launch.sh
Normal file
37
src/launch.sh
Normal file
|
@ -0,0 +1,37 @@
|
|||
#/bin/sh
|
||||
|
||||
# List
|
||||
cd /app
|
||||
DRONE_COMMIT_SHA=$(head -c 8 <<< $DRONE_COMMIT_SHA)
|
||||
|
||||
USERNAME=${USERNAME:-"DRONE CI/CD"}
|
||||
AVATAR=${AVATAR:-"https://github.com/drone/brand/blob/master/logos/png/with-background/drone-logo-white-with-background@2x.png?raw=true"}
|
||||
|
||||
#Init
|
||||
cp template.json build.json
|
||||
|
||||
#Build json
|
||||
if [ "$DRONE_BUILD_STATUS" = "success" ]; then
|
||||
sed -i "s/\$COLOR/3795747/g" build.json
|
||||
sed -i "s/\$BUILD_STATE/Success/g" build.json
|
||||
elif [ "$DRONE_BUILD_STATUS" = "failure" ]; then
|
||||
sed -i "s/\$COLOR/15409955/g" build.json
|
||||
sed -i "s/\$BUILD_STATE/Failed/g" build.json
|
||||
fi
|
||||
|
||||
sed -i "s^\$COMMIT_MESSAGE^$(echo $DRONE_COMMIT_MESSAGE)^g" build.json
|
||||
sed -i "s^\$WORKFLOW_URL^$DRONE_BUILD_LINK^g" build.json
|
||||
sed -i "s^\$COMMIT_USER^$DRONE_COMMIT_AUTHOR^g" build.json
|
||||
sed -i "s^\$COMMIT_HASH^$DRONE_COMMIT_SHA^g" build.json
|
||||
sed -i "s^\$COMMIT_LINK^$DRONE_COMMIT_LINK^g" build.json
|
||||
sed -i "s^\$EVENT^$DRONE_BUILD_EVENT^g" build.json
|
||||
sed -i "s^\$BRANCH^$DRONE_REPO_BRANCH^g" build.json
|
||||
sed -i "s^\$REPO_NAME^$DRONE_REPO^g" build.json
|
||||
sed -i "s^\$REPO_LINK^$DRONE_REPO_LINK^g" build.json
|
||||
sed -i "s^\$JOB_NAME^$DRONE_STAGE_NAME^g" build.json
|
||||
sed -i "s^\$TIMESTAMP^$(date -Iseconds -d @$DRONE_BUILD_FINISHED)^g" build.json
|
||||
sed -i "s^\$USERNAME^$USERNAME^g" build.json
|
||||
sed -i "s^\$AVATAR^$AVATAR^g" build.json
|
||||
|
||||
# Curl
|
||||
curl -X POST -H "Content-Type: application/json" -d "$(cat build.json)" $WEBHOOK_URL
|
44
src/template.json
Normal file
44
src/template.json
Normal file
|
@ -0,0 +1,44 @@
|
|||
{
|
||||
"content": "",
|
||||
"tts": false,
|
||||
"embeds": [
|
||||
{
|
||||
"color": $COLOR,
|
||||
"fields": [
|
||||
{
|
||||
"name": "Repository",
|
||||
"value": "[$REPO_NAME]($REPO_LINK)",
|
||||
"inline": true
|
||||
},
|
||||
{
|
||||
"name": "Ref",
|
||||
"value": "$BRANCH",
|
||||
"inline": true
|
||||
},
|
||||
{
|
||||
"name": "Event - $EVENT",
|
||||
"value": " [`$COMMIT_HASH`]($COMMIT_LINK) $COMMIT_MESSAGE",
|
||||
"inline": false
|
||||
},
|
||||
{
|
||||
"name": "Triggered by",
|
||||
"value": "$COMMIT_USER",
|
||||
"inline": true
|
||||
},
|
||||
{
|
||||
"name": "Workflow",
|
||||
"value": "[Drone link]($WORKFLOW_URL)",
|
||||
"inline": true
|
||||
}
|
||||
],
|
||||
"author": {
|
||||
"name": "$BUILD_STATE: $JOB_NAME"
|
||||
},
|
||||
"timestamp": "$TIMESTAMP"
|
||||
}
|
||||
],
|
||||
"components": [],
|
||||
"actions": {},
|
||||
"username": "$USERNAME",
|
||||
"avatar_url": "$AVATAR"
|
||||
}
|
Loading…
Reference in a new issue