Slack integration for deployments via Capistrano

Updated . Posted . Visible to the public.

You can hook into Slack Show archive.org snapshot when using Capistrano for deployment. The slackistrano Show archive.org snapshot gem does most of the heavy lifting for you. Its default messages are unobtrusive and can be adjusted easily.

When deploying, it posts to a Slack channel like this:

Example

How to integrate

Integrating Slackistrano with Capistrano 3 is fairly simple.

If you are not a Slack admin

Find a Slack workspace admin and have them do steps 1-5 for you. You need to tell them your channel name and send a link to this card.

  1. In a web browser, open Slack's admin settings Show archive.org snapshot . Navigate to " Integrations Show archive.org snapshot ", then " Custom Integrations Show archive.org snapshot ", and open " Incoming WebHooks Show archive.org snapshot ".

  2. Click "Add to Slack" to add a new webhook.

  3. Choose channel, and click the "add" button.

  4. Scroll down to find the "Customize Name" field. Enter "Slackistrano" (or similar) and click the "Save Settings" button.

    • This will not be used for notifications, but clarifies the webhook's purpose when browsing the list of integrations.
    • You don't need to specify an icon, Slackistrano sends its own.
  5. Copy your "Webhook URL" for use in your project.

  6. Add slackistrano to your Gemfile, in your :deploy group, and bundle your project.

  7. Add the following to your Capfile.

    # Slack notifications
    require 'slackistrano/capistrano'
    set :slackistrano, {
      channel: '#your-channel',
      webhook: 'https://hooks.slack.com/services/your/webhook/url',
    }
    
  8. Optional: Tweak your deployment messages Show archive.org snapshot . See the attached file for our default message formatting. Your Capfile needs to be adjusted accordingly:

    # Slack notifications
    require 'slackistrano/capistrano'
    require_relative 'lib/capistrano/slackistrano'
    set :slackistrano, {
      klass: Slackistrano::CustomMessaging,
      channel: '#your-channel',
      webhook: 'https://hooks.slack.com/services/your/webhook/url',
    }
    
  9. Test Slackistrano:

    cap staging slack:deploy:test
    
  10. When you are satisfied, do a real deploy to confirm everything works.

Profile picture of Arne Hartherz
Arne Hartherz
Last edit
Arne Hartherz
License
Source code in this card is licensed under the MIT License.
Posted by Arne Hartherz to makandra dev (2015-03-19 17:33)