Heroku for ChatOps: How to Start and Monitor Deployments From Slack

cover
4 Jun 2024

In our last two articles, we explored how to configure CI/CD for Heroku using Heroku pipelines. When viewing a pipeline within the Heroku dashboard, you can easily start a deployment or promote your code from one environment to the next with the click of a button. From the dashboard, you can monitor the deployment and view its progress.

This all works really well, assuming that you have Heroku open in your browser. But, what if you wanted to do it all from Slack?

Software engineers use a lot of apps at work. Throughout the day, we are constantly bouncing between Zoom meetings, Jira tasks, Slack conversations, GitHub, email, our calendar, and our IDE. This context switching can be exhausting and also lead to a lot of visual clutter on our monitors.

Sometimes, it’s nice to just live in Slack, and that’s why many tools offer Slack integrations. With these Slack integrations, you can monitor various processes and even use shortcut commands to trigger actions.

Heroku ChatOps, the Heroku Slack integration, allows you to start and monitor deployments directly from Slack. In this article, we’ll explore some of the Slack commands it offers.

Getting Started

If you’d like to follow along throughout this tutorial, you’ll need a Heroku account and a GitHub account. You can create a Heroku account here, and you can create a GitHub account here.

The demo app that we will use with our Heroku pipeline in this article is deployed to Heroku, and the code is hosted on GitHub.

Create Our Heroku Pipeline

We won’t go through the step-by-step process of creating a Heroku pipeline in this article. Refer to these articles for a walkthrough of creating a Heroku pipeline:

You can also read the Heroku docs for Heroku pipelines.

Configuring your Heroku pipeline includes the following steps:

  1. Create a GitHub repo.
  2. Create a Heroku pipeline.
  3. Connect the GitHub repo to the Heroku pipeline.
  4. Add a staging app to the pipeline.
  5. Add a production app to the pipeline.

The other activities that you’ll see in those articles, such as configuring review apps, Heroku CI, or automated deployments are optional. In fact, for the purposes of this demo, I recommend not configuring automated deployments, since we’ll be using some Slack commands to start the deployments.

When you’re done, you should have a Heroku pipeline that looks something like this:

Example Heroku pipeline

Connect to Slack

Now that you have your Heroku pipeline created, it’s time for the fun part: integrating with Slack. You can install the Heroku ChatOps Slack app here.

Clicking that link will prompt you to grant the Heroku ChatOps app permission to access your Slack workspace:

Grant Heroku ChatOps access to your Slack workspace

After that, you can add the Heroku ChatOps app to any Slack channel in your workspace.

Add the Heroku ChatOps app

After adding the app, type /h login and hit Enter. This will prompt you to connect your Heroku and GitHub accounts. You’ll see several Heroku OAuth and GitHub OAuth screens where you confirm connecting these accounts.

(As a personal anecdote, I found that it took me several tries to connect my Heroku account and my GitHub account. It may be due to having several Slack workspaces to choose from, but I’m not sure.)

After connecting your Heroku account and your GitHub account, you’re ready to start using Heroku in Slack.

Connect your Heroku and GitHub accounts

View All Pipelines

To view all deployable pipelines, you can type /h pipelines:

View all pipelines

View Pipeline Info

To see information about any given pipeline, type /h info <PIPELINE_NAME>. (Anything you see in angle brackets throughout this article should be replaced by an actual value. In this case, the value would be the name of a pipeline — for example, “heroku-flow-demo-pipeline”.)

View pipeline info

View Past Releases

To view a history of past releases for any given pipeline, type /h releases <PIPELINE_NAME>.

View past releases

This command defaults to showing you past releases for the production app, so if you want to see the past releases for the staging app, you can type /h releases <PIPELINE_NAME> in <STAGE_NAME>, where <STAGE_NAME> is “staging.”

View past staging releases

Deploy to Staging

Now that we know which pipelines are available, we can see information about any given pipeline along with when the code was last released for that pipeline. We’re ready to trigger a deployment.

Most engineering organizations have a Slack channel (or channels) where they monitor deployments. Imagine being able to start a deployment right from that channel and monitor it as it goes out! That’s exactly what we’ll do next.

To start a deployment to your staging environment, type /h deploy <PIPELINE_NAME> to <STAGE_NAME>, where <STAGE_NAME> is “staging.”

Deploy to staging

After running that command, an initial message is posted to communicate that the app is being deployed. Shortly after, you’ll also see several more messages; this time, in a Slack thread on the original message:

Slack messages are sent when deploying to staging

If you want to verify what you’re seeing in Slack, you can always check the Heroku pipeline in your Heroku dashboard. You’ll see the same information: The staging app has been deployed!

Staging app shown in the Heroku dashboard

Promote to Production

Now, let’s promote our app to production. Without the Slack commands, we could navigate to our Heroku pipeline, click the “Promote to production” button, and then confirm that action in the modal dialog that appears. However, we’d prefer to stay in Slack.

To promote the app to production from Slack, type /h promote <PIPELINE_NAME>.

Promote to production

Just like with the staging deployment, an initial Slack message will be sent, followed by several other messages as the production deployment goes out:

Slack messages sent when promoting to production

And — voilà — the latest changes to the app are now in production!

Conclusion

Now, you can start and monitor Heroku app deployments all from Slack — no need to context switch or move between multiple apps.

For more use cases and advanced setups, you can also check out the docs.

Happy deploying!