Codyfight webhook utility for sending deployment notifications to Discord or any other webhook service.
yarn add codyfight-webhook
or
npm install codyfight-webhook
This file contains utility functions for sending Discord webhook messages.
-
sendDiscordMessage(webhookUrl: string, messageType: string, pipelineUrl: string): Promise<void>
- Sends a Discord webhook message with the specified webhook URL and message type.
-
Parameters:
-
webhookUrl
: The URL of the Discord webhook. -
messageType
: The type of message to send (success or failure). -
pipelineUrl
: The URL of the pipeline.
-
-
Returns:
Promise<void>
This file is the main interface for sending Discord webhook messages using the discordWebhook.js
utility functions.
It Provides a command-line interface for sending Discord webhook messages.
node discord.js -u <webhookUrl> -p <pipelineUrl> -t <messageType>
-
-u, --url <webhookUrl>
: Specifies the URL of the Discord webhook. (Required) -
-p, --pipeline <pipelineUrl>
: Specifies the URL of the pipeline. (Required) -
-t, --type <messageType>
: Specifies the type of message to send (success or failure). Default is success. (Optional)
-
Send a success message to a Discord webhook:
node discord.js -u <webhookUrl> -p <pipelineUrl>
-
Send a failure message to a Discord webhook:
node discord.js -u <webhookUrl> -p <pipelineUrl> -t failure
Important: If you are using AWS CodeBuild, you can use the following node.js script to wrap the discord.js
script and send Discord webhook notifications after each CodeBuild run.
send_discord_notification.js
const { runDiscordNotification } = require("codyfight-webhook");
runDiscordNotification();
Make sure the environment variables BRANCH_NAME
, WEBHOOK_DISCORD_URL
and WEBHOOK_PIPELINE_URL
are set in your CodeBuild project.
buildspec.yml
To integrate the Discord webhook notification into your AWS CodeBuild pipeline, add the following commands to the post_build
phase of your buildspec.yml
file:
version: 0.2
env:
variables:
BRANCH_NAME: '#{SourceVariables.BranchName}'
parameter-store:
WEBHOOK_DISCORD_URL: '/CodeBuild/codyfight-web-prod/WEBHOOK_DISCORD_URL'
WEBHOOK_PIPELINE_URL: '/CodeBuild/codyfight-web-prod/WEBHOOK_PIPELINE_URL'
# ... other environment variables
phases:
# ... other phases
post_build:
on-failure: ABORT
commands:
- node send_discord_notification.js
Make sure to replace send_discord_notification.js
with the filename of your script.
With these instructions, your Discord webhook notification will be sent after each CodeBuild run, indicating whether the build was successful or failed.