Giter VIP home page Giter VIP logo

drone-discord's Introduction

drone-discord

logo

Drone / Woodpecker plugin for sending message to Discord channel using Webhook.

GoDoc codecov Go Report Card Docker Pulls

Webhooks are a low-effort way to post messages to channels in Discord. They do not require a bot user or authentication to use. See more api document information. For the usage information and a listing of the available options please take a look at the docs.

Sending discord message using a binary, docker or Drone CI.

Features

  • Send Multiple Messages
  • Send Multiple Files

Build or Download a binary

The pre-compiled binaries can be downloaded from release page. Support the following OS type.

  • Windows amd64/386
  • Linux arm/amd64/386
  • Darwin amd64/386

With Go installed

go get -u -v github.com/appleboy/drone-discord

or build the binary with the following command:

export GOOS=linux
export GOARCH=amd64
export CGO_ENABLED=0
export GO111MODULE=on

go test -cover ./...

go build -v -a -tags netgo -o release/linux/amd64/drone-discord

Usage

There are three ways to send notification.

Usage from binary

drone-discord \
  --webhook-id xxxx \
  --webhook-token xxxx \
  --message "Test Message"

Usage from docker

docker run --rm \
  -e WEBHOOK_ID=xxxxxxx \
  -e WEBHOOK_TOKEN=xxxxxxx \
  -e WAIT=false \
  -e TTS=false \
  -e USERNAME=test \
  -e AVATAR_URL=http://example.com/xxxx.png \
  -e MESSAGE=test \
  appleboy/drone-discord

Usage from drone ci

Send Notification

Execute from the working directory:

docker run --rm \
  -e WEBHOOK_ID=xxxxxxx \
  -e WEBHOOK_TOKEN=xxxxxxx \
  -e WAIT=false \
  -e TTS=false \
  -e USERNAME=test \
  -e AVATAR_URL=http://example.com/xxxx.png \
  -e MESSAGE=test \
  -e DRONE_REPO_OWNER=appleboy \
  -e DRONE_REPO_NAME=go-hello \
  -e DRONE_COMMIT_SHA=e5e82b5eb3737205c25955dcc3dcacc839b7be52 \
  -e DRONE_COMMIT_BRANCH=master \
  -e DRONE_COMMIT_AUTHOR=appleboy \
  -e [email protected] \
  -e DRONE_COMMIT_MESSAGE=Test_Your_Commit \
  -e DRONE_BUILD_NUMBER=1 \
  -e DRONE_BUILD_STATUS=success \
  -e DRONE_BUILD_LINK=http://github.com/appleboy/go-hello \
  -e DRONE_JOB_STARTED=1477550550 \
  -e DRONE_JOB_FINISHED=1477550750 \
  -v $(pwd):$(pwd) \
  -w $(pwd) \
  appleboy/drone-discord

Declarative environment config usage

You can get more information about how to use this plugin in drone.

- name: msg status
  image: appleboy/drone-discord
  settings:
    webhook_id:
      from_secret: discord_id
    webhook_token:
      from_secret: discord_token
    message: "{{#success build.status}}✅{{else}}❌{{/success}}  Repository `[{{repo.name}}/{{commit.branch}}]` triggered by event `[{{uppercase build.event}}]` for build.\n    - Commit [[{{commit.sha}}]({{commit.link}})]\n    - Author `[{{commit.author}} / {{commit.email}}]`\n    - Message: {{commit.message}}    - Drone build [[#{{build.number}}]({{build.link}})] reported `[{{uppercase build.status}}]` at `[{{datetime build.finished \"2006.01.02 15:04\" \"\"}}]`\n"
    when:
      status: [ success, failure, changed ]
- name: multi line msg status 
  ...
    message: >
      Line one
      Line two

Testing

Test the package with the following command:

make test

drone-discord's People

Contributors

appleboy avatar bafor avatar byreqz avatar c2h5oh avatar fgierlinger avatar gigafyde avatar more-pepsi avatar qwerty287 avatar sapk avatar utarwyn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

drone-discord's Issues

Helper since - evaluation error

When trying to use helper "since" I got this from Drone:

Evaluation error: Helper since called with argument 0 with type float64 but it should be int64

Used like:

  - name: notify-end
    image: appleboy/drone-discord
    settings:
      webhook_id: THEID
      webhook_token: THETOKEN
      message: "
        {{#success build.status}}
          build {{build.number}} deployed in {{since build.started}}.
        {{ else }}
          build {{build.number}} failed in {{since build.started}}. See {{build.link}}.
        {{/success}}"

check support for 1.0.0

seems right now that 1.0.0 support isn't functioning, I had to set up drone.yml with

---
kind: pipeline
name: default
  
steps:
- name: discord
  pull: default
  image: appleboy/drone-discord
  environment:
    DISCORD_WEBHOOK_ID:
      from_secret: discord_webhook_id
    DISCORD_WEBHOOK_TOKEN: 
      from_secret: discord_webhook_token
  when:
    event: [ push, tag, pull_request ]
    status: [ changed, failure, success ]
  message: >
    {{#success build.status}}
      build {{repo.name}} {{build.branch}} {{build.number}} succeeded. Good job.
    {{else}}
      build {{repo.name}} {{build.branch}} {{build.number}} failed. Fix me please. {{build.link}}
    {{/success}}

but all I get is:
screen shot 2018-11-11 at 8 37 18 pm

Doesn't seem to run, says step successful?

Hey there, somehow I got this to run the first time, but every time after it looks like it just seems to skip the actual step but comes up as a pass. Here's my step:

- name: discord start notification
  image: appleboy/drone-discord
  settings:
    webhook_id:
      from_secret: discord_webhook_id
    webhook_token:
      from_secret: discord_webhook_id
    message: "Rebuilding..."

Something I'm doing wrong maybe? Triple checked the secrets are correct. I can run it in a docker container just fine with something like below with test env variables:

docker run -e WEBHOOK_ID=$HOOK_ID -e WEBHOOK_TOKEN=$HOOK_TOKEN -e MESSAGE=test appleboy/drone-discord

Not sure if this is an issue or if I'm missing something?

Thanks!

Plugin seems to no longer be working even with super barebones pipeline

I want to believe im doing it wrong, but even with the most barebones settings, this is not sending notifications. I have verified my webhook url is correct by running a curl command which is sending notifications to discord

here is my bare bones .drone.yml file which is not posting to discord

kind: pipeline
type: docker
name: Testing droneXdiscord integration

steps:
- name: discord notification
  image: appleboy/drone-discord
  settings:
    webhook_id:
      from_secret: discord_webhook_id
    webhook_token:
      from_secret: discord_webhook_token
    message: "Testing from drone pipeline"

For reference, this curl command (using the same exact webhook id and token) works

curl --json '{"username": "Drone CI", "avatar_url": "https://miro.medium.com/v2/resize:fit:1358/0*AqO_2lNemh_Fl9Gm.png","content": "Testing from curl"}' https://discord.com/api/webhooks/<webhook_id>/<webhook_token>

And just for good measure, tried running the binary by itself which DOES work

./drone-discord -webhook-id=<id> -webhook-token=<token> -message="test"

Intermittent X509 Certificate Signed by Unknown Authority

Hello!
Well, i've been using this plugin in a drone ci kubernetes environment and this error keeps occuring.
Sometimes the pipeline just fails for this reason showed below
image

The only thing this step does is send a message in my discord channel through a webhook. The .drone.yml is here:

kind: pipeline
type: kubernetes
name: pr-open
trigger:
  event:
    - pull_request
  action:
    - opened

steps:
  - name: discord
    pull: always
    image: appleboy/drone-discord
    settings:
      message: "## New PR 🥳🚀 \n [${DRONE_PULL_REQUEST_TITLE}](${DRONE_REPO_LINK}/pull/${DRONE_PULL_REQUEST})"
      webhook_id: '<my-discord-id>'
      webhook_token: '<my-discord-token>'

Did this happen to anyone else? Does someone have a clue in how to solve this?
Just a reminder, the error is intermittent... so after a few restarts, it works!

secrets not working as documented

I found a way to export the discord_id and discord_token to secrets, but not as documented. My way:

   - name: notification on failure
      image: appleboy/drone-discord
      settings:
          webhook_id:
              from_secret: discord_webhook_id
          webhook_token:
              from_secret: discord_webhook_token

The documentation says, that the parameter secrets should be used, but there was no way that I managed to make it work that way.

   - name: notification on failure
      image: appleboy/drone-discord
      settings:
          secrets: [discord_webhook_id, discord_webhook_token]

Am I doing something wrong, or is an update of the documentation required?

Support upload file

like curl command:

curl -H 'Content-Type: multipart/form-data' \
-X POST \
-F "file=@file_path" $DISCORD_WEBHOOK_URL

Discord Embed notification

At the moment when a custom message and a color is defined, the notification goes out as an embed, but everything is send as title, can this be changed to description? This way we can use markdown hyperlinks and everything won't be in Bold.

Usable variables

Hello,

I would like to know why i can use some variable but not all.
For example, i would like to use commit.message but it returns blank.
However others variables that are declared on this page are usable (like build.number).

Do you know why ?
Thank you for your work :)

Regards,

Variables build.started and build.finished and Duration Not Working

This is a continuation of #22. I am trying to use the following at the end of my .drone.yml file:

- name: discord notification
  when:
    status:
      - success
      - failure
  image: appleboy/drone-discord
  settings:
  webhook_id: 1234567890
  webhook_token: 123456789012345678901234567890
  message: "{{#success build.status}}✅ **mangos-classic - Build #{{build.number}}**\n- Started at {{datetime build.started \"2006-01-02 15:04:05\" \"America/Chicago\"}} and finished at {{datetime build.finished \"2006-01-02 15:04:05\" \"America/Chicago\"}}\n- Build Duration: {{duration build.started build.finished}}\n{{build.link}}{{else}}❌ **mangos-classic - Build #{{build.number}}\n- Started at {{datetime build.started \"2006-01-02 15:04:05\" \n\"America/Chicago\"}} and finished at {{datetime build.finished \"2006-01-02 15:04:05\" \"America/Chicago\"}}\n- Build Duration: {{duration build.started build.finished}}\n{{build.link}}{{/success}}"

However it's not obeying the timezone I have set (America/Chicago) and is showing times in UTC (which I noted also happens in the example you provided in #22), and the build.started and build.finished are showing the same times.

The duration is also showing 0s, likely because build.started and build.finished are both the same time.

Any ideas on these issues?

build.branch/message/author not working

Hi.

I have the following problem with build variables not showing in the message.

Config:

message: >
      {{#success build.status}}
        build {{build.number}} succeeded.
      {{else}}
        build {{build.number}} failed.  
        Changes: {{build.branch}} / {{build.message}} from {{build.author}}.  
        See: {{build.link}}
      {{/success}}

Message on discord:

build 126 failed.
  Changes:  /  from .
  See: https://drone.example.org/Group/Project/126

The job on drone:
grafik

Setup always reported success on Kubernetes

Hi

I posted on discourse earlier today here: https://discourse.drone.io/t/notification-plugins-always-reports-success/7538

Basically I have switched to running my pipelines with the Kubernetes runner and it has changed how step information is passed from one to another.
So the discord plugin will always report success.

And there is a known limitation in drone, https://docs.drone.io/runner/kubernetes/overview/#known-issues--differences

Is this something that would be possible to fix?

no message on discord

i'm not getting a message on discord with the 1.0.0 drone yaml syntax
have I got this right?

kind: pipeline
name: default

steps:

- name: notify
  image: appleboy/drone-discord:1.0.0
  pull: always
  settings:
    webhook_id:
      from_sercet: discord_webhook_id
    webhook_token:
      from_sercet: discord_webhook_token
    message: testing123

Suggestion: Nickalert on fail to build.

First of all: Great drone.io plugin, thanks for making it available.

I use the default message of the plugin, because it uses colors in the message. (Green if successful, red if not)

Since I muted the channel, I would like to be notified when a build fails. My idea for this would be to set discord-Ids for a nickalert.

It would be optimal if Ids could be set for fail and success.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.