Bitrise + Discord

MJ Manaog
4 min readOct 17, 2020

How to setup Discord to Bitrise to send a custom build message in your server’s channel using webhook.

What is Bitrise?

Bitrise is a Continuous Integration and Delivery (CI/CD) Platform as a Service (PaaS) with a main focus on mobile app development (iOS, Android, React Native, Flutter, and so on). It is a collection of tools and services to help you with the development and automation of your software projects.
https://www.bitrise.io/

Why CI/CD is important?

CICD practicies of continuous integration and continuous delivery helps DevOps teams ship higher quality software, faster, for improved software deployment.
https://about.gitlab.com/blog/2019/06/27/positive-outcomes-ci-cd/

But first, you must set up your project in Bitrise.

How to set-up Bitrise for your Android Appliction: https://medium.com/@mjmanaog/setup-android-bitrise-ci-cd-e9953974f927

Let’s get started!

Step 1. Setting Up Channel’s Webhook in Discord

  1. In your Discord server, select a channel
  2. Click ⚙️ Edit Channel

3. Click Integrations

4. Click Create Webhook (if you do not have an existing webhook)

5. Add Image(Optional), Name, check the selected Channel, then Copy Webhook URL, then click Save Changes

Step 2. Set-up your application’s workflow in Bitrise

  1. Select the workflow where you want to add the process of sending of notification in Discord
  2. Add new process: Send a Discord message below the Deploy to Bitrise.io

3. Add Discord Webhook URL in Send a Discord message process

4. Paste your Discord Webhook URL in the new variable

This is how it will look like upon a successful build:

5. Add new process: Script below the Send A Discord Message process.

This is where we will add our custom notification message.

6. Paste this bash script in Script Content

export BUILD_NO=$BITRISE_BUILD_NUMBER
export DISCORD_URL=$DISCORD_WEBHOOK
curl -H "Content-Type: application/json" -X POST "$DISCORD_URL" --data "{\"username\": \"Bitrise Notification\", \"content\": \"Hello, this is a test build! \nBitrise Build Number $BUILD_NO \", \"embeds\": [{\"title\": \"Click this to view QR Code\", \"url\": \"$BITRISE_PUBLIC_INSTALL_PAGE_QR_CODE_IMAGE_URL\"}]}"

You can also use the existing Bitrise variables in your script to make your notification more verbose.

To break down this script:

  • We’ve created new variables using export, APK_URL, BUILD_NO, and DISCORD_URL to make the Bitrise built-in variables (e.g. $BITRISE_PUBLIC_INSTALL_PAGE_URL)available in our cURL command and reuse it
  • curl — to transfer data to or from a sever
  • -H — header
  • -X — command. We use POST command in our case
  • --data — data to pass. Must be wrapped in “{}”
  • Discord webhook available fields: https://discord.com/developers/docs/resources/webhook#get-guild-webhooks
  • \"username\": \"Bitrise Notification\", — name
  • \"content\": \"Hello, this is a test build \nBitrise Build Number $BUILD_NO \", — main-content/message
  • \"embeds\": [{\"title\": \"Click this to view the link\", \"url\": \"https://www.google.com/\"}] —If you want to display a clickable link
  • Available embeds (images/descriptions/author) — https://gist.github.com/Birdie0/78ee79402a4301b1faf412ab5f1cdcf9

This is how your custom discord message will look like:

You can also test it locally by creating a text file > paste the script > Save as discordscript.sh > open terminal > Enter this command : bash yourscript.sh

Note: You must change the variables to at least dummy strings to test it locally.

7. Save your Workflow

8. Try to Build it manually, and see the magic! ✨

I am still learning in creating a bash scripts, if you have some suggestion(s)/comments please leave a message.

That’s all! Thank you.

--

--