Introduction to ChatOps with Acquia BLT and Slack
In a modern DevOps world, a large part of the deployment pipeline is automated across multiple tools. Most DevOps pipelines validate, test, build, and deploy code, all automatically. It can be tempting to trust the system to just handle these steps. When something goes wrong, how long does it take you to find out? Does your QA team often wonder why a ticket that is marked for them to test doesn’t seem to actually be available? This is where ChatOps comes in. ChatOps turns your chat messenger into a communication hub for the team and the automated DevOps pipeline. Acquia’s Build & Launch Tool comes with Slack messaging built in. This guide will walk you through a basic ChatOps set up with BLT and Slack.
Getting Slack Ready
To use Slack as your hub for automated messaging, you’ll need a channel that can receive messages via a webhook. There are two schools of thought: some prefer using a separate channel, dedicated to devops messaging; other teams prefer having the devops messages right in with the rest of the team chat. Which is right for your team is largely a matter of preference.
Teams that prefer to have devops messaging in a separate channel usually do so because devops messaging can get repetitive and clutter the general chat with messages, obscuring real discussion between developers. Placing devops messages in their own, dedicated channel allows team members to set appropriate levels of notifications without interfering with the team's normal discussions.
On the other hand, some teams prefer to have devops right in the middle of everything. It’s important to know when things are happening in the repository and when deployments are under way. Having devops messages appear in the main team chat forces everyone to be aware of what’s happening in case.
Regardless of your decision, you’ll need to setup a webhook to receive messages. Slack makes this very easy.
- Create a new Slack app or open the settings for an existing one.
- Select the Incoming Webhooks in the left navigation and click Activate Incoming Webhooks if it is not already enabled.
- Click Add New Webhook to Workspace. Pick the channel you want to send devops messages to and click Authorize.
- You’ll receive a unique webhook URL; hold on to this for later.
Connecting Slack to Acquia BLT
BLT is a wonderful way to automate a large part of your Drupal maintenance on Acquia. It is easy to configure via YAML files and has a large number of built-in scripts that require little to no setup and provide great benefit. Even better, Acquia BLT has a Slack connection built-in, you just have to provide your webhook URL in the configuration file!
Adding Slack communication to your BLT operations is as simple as editing the blt.yml
file. Just add this configuration to your blt.yml
and push the code to Acquia. Make sure you use your unique webhook URL from the previous section.
slack:
webhook-url: “https://my.slack.webhook.url/########”
Once this configuration is deployed to Acquia you should start seeing messages in your Slack channel like the message below.
Bonus: Connecting Your Code Repository
Acquia BLT provides chatops for an important part of your devops pipeline. It helps cover that “last mile” where code is actually deployed to Acquia. What about the rest of your pipeline? Chatops can bring in the rest of your code operations as well, truly making Slack the hub for your team's devops pipeline.
Git is the most commonly used version control system and most of the major Git remote providers already have Slack apps. This list includes Bitbucket, GitHub, and GitLab. Connecting each of these apps is generally very simple!
Bitbucket
Bitbucket makes this wonderfully simple. First, install the Bitbucket Cloud Slack app. With the app installed, you can subscribe any channel to any repository with a simple slash command.
/bitbucket connect <repository URL>
This will connect the channel to your repository and open a browser tab where you can select the relevant events in Bitbucket. By default nearly everything is selected, providing a robust view of your repository activity.
GitHub
GitHub also provides a helpful Slack app. Installing the GitHub for Slack app will provide a slash command, subscribing the channel to repository activity.
/github subscribe [repository name]
The GitHub for Slack app will post in the subscribed Slack channel with any repository activity. This will keep your development team aware of any changes or actions required.
GitLab
GitLab doesn’t provide an app integration for notifications but it can use the webhook you generated earlier! To set up the Slack notifications service, follow these steps:
- Go to your project settings and select Integrations.
- Select Slack notifications.
- Select the Active checkbox in the Enable integration section.
- Select the triggers you would like notifications for.
- Enter the webhook URL you created earlier.
- Select Save Changes.
GitLab should now send notifications to the same channel that Acquia BLT notifies!
That’s How It’s Done!
Setting up ChatOps with Acquia BLT is that easy. This messaging will appear for database copies and backups, deployments, and code switches. If you also connected your code repository, you should have a complete picture of your code and deployment activity. Now your team will have a consistently up-to-date awareness of your Acquia application status!