Skip to content

Serverless solution for sending build status from one of many CI services to Discord via webhook.

License

Notifications You must be signed in to change notification settings

symboxtra/universal-ci-discord-webhook

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

70 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CI Service 🡒 Discord Webhook

If you've been looking for a way to get build reports from your CI service to Discord, look no further. You've come to the right place.

Providers

The following CI services are currently supported and will be autodetected when you run the appropriate send.XXX script:

CI Service Script Support Status
AppVeyor send.ps1 AppVeyor Build Status
Jenkins send.ps1 send.sh Jenkins Build Status
Travis send.sh Travis Build Status

We're always looking to support more! Feel free to implement support yourself or open an issue and ask.

Guide

  1. Create a Webhook in your Discord Server (Guide).

  2. Copy the Webhook URL.

  3. Go to your CI platform's global or repository specific settings and look for a section entitled Environment or Environment Variables

  4. Add an environment variable named WEBHOOK_URL and paste the copied Webhook URL from the previous step.

    It's wise to keep this URL private.

    Most platforms support Secure Environment Variables, offer some form of encryption, or allow you to prevent the value from showing in the build logs entirely.

    Example from Travis CI

    Add environment variable in Travis CI

  5. Add the following commands to the success and failure sections of your CI provider's pipeline.

    Example for AppVeyor

    on_success:
    - ps: Invoke-RestMethod https://raw.githubusercontent.com/symboxtra/universal-ci-discord-webhook/master/send.ps1 -o send.ps1
    - ps: if ($env:WEBHOOK_URL.length -ne 0) { ./send.ps1 success $env:WEBHOOK_URL } else { Write-Host "WEBHOOK_URL inaccessible." } # Send Webhook only when secure env vars can be decrypted
    
    on_failure:
    - ps: Invoke-RestMethod https://raw.githubusercontent.com/symboxtra/universal-ci-discord-webhook/master/send.ps1 -o send.ps1
    - ps: if ($env:WEBHOOK_URL.length -ne 0) { ./send.ps1 failure $env:WEBHOOK_URL } # Send Webhook only when secure env vars can be decrypted

    Example for Travis CI

    after_success:
      - curl https://raw.githubusercontent.com/symboxtra/travis-ci-discord-webhook/master/send.sh > send.sh && chmod +x send.sh
      - ./send.sh success $WEBHOOK_URL
    after_failure:
      - curl https://raw.githubusercontent.com/symboxtra/travis-ci-discord-webhook/master/send.sh > send.sh && chmod +x send.sh
      - ./send.sh failure $WEBHOOK_URL

    The first line downloads the script file and makes it executable (if applicable). The second line sends the webhook.

Strict Mode

If you prefer that the script fail and return a non-zero exit code upon any error, strict mode can be enabled by passing strict as the third parameter to the script. This is mainly intended for testing.

./send.sh success $WEBHOOK_URL strict

Caveats

On some CI platforms, secure environment variables are not available during third party pull request builds. The webhook will not send notification of these builds.

To prevent your CI build from erroring, the scripts in this repository exit with a non-zero exit code only when strict mode is enabled. For added safety/sanity, the script call can be wrapped in a length check on WEBHOOK_URL, as seen in the AppVeyor example, or can be combined with || true to eat any possible non-zero exit codes.

About

Serverless solution for sending build status from one of many CI services to Discord via webhook.

Resources

License

Stars

Watchers

Forks

Packages

No packages published