whoami

Lucas Jenß

cat /etc/motd

The Coding Journal ツ — Notes taken on an epic coding journey. Technical solutions, debugging notes, and practical guides from the trenches of software development.

Close-up of white dominoes with black dots standing on green felt surface, shallow depth of field, focused mood

ls -la ~/languages/

total 8
drwxr-xr-x
▶ PHP
▶ Ruby
▶ Scala
▶ C#
▶ JavaScript
▶ Objective-C
▶ Shell Scripting

ls -la ~/toolchain/

total 7
drwxr-xr-x
▶ Typo3
▶ Akka
▶ Capistrano
▶ Git
▶ MAMP
▶ Adobe Illustrator
▶ NSTrackingArea (Cocoa)

uname -a

platforms
drwxr-xr-x
▶ Mac OS X
▶ Unix

Writing a Capistrano plugin for Slack deployment alerts

A deployment is easier to trust when the team can see what happened without opening a terminal or checking several monitoring tools. Capistrano already provides lifecycle hooks for this purpose, making it a practical base for sending deployment started, succeeded, and failed messages to Slack.

A small notification plugin can capture the application name, branch, environment, release revision, and person who launched the task. It can then post a concise message to a channel used by developers, testers, and operations staff. The key is to keep deployment logic separate from Slack transport code.

This approach suits teams working across Australian time zones, where a Sydney developer might deploy while colleagues in Melbourne or Perth are offline. A clear message in a shared channel prevents the familiar “Has this reached staging yet?” exchange and leaves a useful audit trail for the next morning.

The example below targets Capistrano 3 and Ruby. It uses Slack’s incoming webhook API, but the design can be adapted for a bot token or an internal notification service. The plugin remains deliberately small so it can be copied into an existing deployment setup and adjusted without introducing a large dependency.

Decide what the plugin should report

A useful deployment message answers four questions: what application changed, where it was deployed, whether it worked, and which revision is running. It should also include a link to the build or deployment record when one exists.

Avoid posting every command executed by Capistrano. A production channel can become noisy very quickly, especially when a team deploys several times during an afternoon. A start message and a final status message are generally enough:

:rocket: shop deployed to staging
Revision: 8c4e91a
By: sam

For a failure, include the stage and revision, then point engineers to the deployment log. Do not place secrets, environment variables, or full exception traces in Slack. The channel is a collaboration tool, not a secure log store.

Build the plugin around lifecycle hooks

Capistrano exposes hooks such as deploy:started, deploy:finished, and deploy:failed. A plugin can subscribe to these events and execute a Ruby method when each one fires. This is preferable to inserting notification commands into individual application deploy files.

Create a file such as lib/capistrano/slack_notify.rb:

require "net/http"
require "json"
require "uri"

namespace :load do
  task :defaults do
    set :slack_webhook_url, ENV["SLACK_WEBHOOK_URL"]
    set :slack_channel, ENV.fetch("SLACK_CHANNEL", "#deployments")
    set :slack_username, ENV.fetch("SLACK_USERNAME", "Capistrano")
  end
end

namespace :slack do
  task :notify_started do
    SlackNotify.post(
      text: ":rocket: #{fetch(:application)} deployment started",
      colour: "#439FE0"
    )
  end

  task :notify_finished do
    SlackNotify.post(
      text: ":white_check_mark: #{fetch(:application)} deployed to #{fetch(:stage)}",
      colour: "#36A64F"
    )
  end

  task :notify_failed do
    SlackNotify.post(
      text: ":x: #{fetch(:application)} deployment failed on #{fetch(:stage)}",
      colour: "#D00000"
    )
  end
end

after "deploy:started", "slack:notify_started"
after "deploy:finished", "slack:notify_finished"
after "deploy:failed", "slack:notify_failed"

The hook names are intentionally explicit. They make the plugin easy to inspect and allow a project to override or disable one notification without changing the HTTP client.

Send a small, safe Slack payload

The SlackNotify class should handle transport details independently from Capistrano. Slack webhooks accept JSON, so the implementation can use Ruby’s standard library and avoid adding another gem to the deployment bundle.

module SlackNotify
  module_function

  def post(text:, colour:)
    url = fetch(:slack_webhook_url)
    return warn("Slack notifications disabled") if url.to_s.empty?

    payload = {
      username: fetch(:slack_username),
      channel: fetch(:slack_channel),
      attachments: [
        {
          fallback: text,
          text: text,
          color: colour
        }
      ]
    }

    uri = URI(url)
    request = Net::HTTP::Post.new(uri)
    request["Content-Type"] = "application/json"
    request.body = JSON.generate(payload)

    response = Net::HTTP.start(
      uri.hostname,
      uri.port,
      use_ssl: uri.scheme == "https"
    ) { |http| http.request(request) }

    warn("Slack returned #{response.code}") unless response.is_a?(Net::HTTPSuccess)
  rescue StandardError => e
    warn("Slack notification error: #{e.message}")
  end
end

The rescue clause is important. A Slack outage should not normally block a production deployment. The deployment command remains the source of truth, while Slack acts as a convenience notification layer. If notifications are operationally critical, fail-fast behaviour can be made configurable rather than hard-coded.

For teams that publish content or commerce sites, this distinction matters. A failed chat request should not leave a working release in an uncertain state, particularly during a busy campaign or an Australian retail event such as Boxing Day sales.

Load the plugin from the deployment project

Store the Ruby file in the repository, for example under lib/capistrano/slack_notify.rb, and load it from Capfile:

$LOAD_PATH.unshift File.expand_path("lib", __dir__)

require "capistrano/setup"
require "capistrano/deploy"
require "capistrano/slack_notify"

Set deployment-specific values in the stage files. Keep the webhook outside version control:

# config/deploy/staging.rb
set :slack_channel, "#staging-deploys"

# config/deploy/production.rb
set :slack_channel, "#production-deploys"

The webhook should be supplied by the CI environment, encrypted credentials store, or deployment host:

export SLACK_WEBHOOK_URL="https://hooks.slack.com/services/..."
cap production deploy

A deployment platform may expose secrets differently, so the plugin should read the value at runtime rather than write it to deploy.rb. Rotate the webhook immediately if it appears in Git history or a public build log.

Add useful deployment metadata

The first version can report only the application and stage, but deployment messages become much more valuable when they include revision and operator details. Capistrano commonly provides fetch(:current_revision), although it may be unavailable during the earliest hook.

A helper can safely gather optional values:

def deployment_context
  {
    application: fetch(:application, "application"),
    stage: fetch(:stage, "unknown"),
    revision: fetch(:current_revision, "unknown"),
    user: ENV["USER"] || ENV["USERNAME"] || "unknown"
  }
end

Use short text in the main message and place additional values in Slack fields if the channel needs them. Include a commit URL only when the repository host and revision are known. A message linking to a specific change is more useful than a generic “deployment completed” alert.

This is also where local team conventions help. Australian developers often use “staging” and “production” plainly, while an organisation may call its customer-facing environment “live”. Match the names already used by the team so alerts are understood by people who are not involved in the deployment code.

Test success, failure, and missing configuration

Test the plugin without deploying the application. A simple approach is to stub Net::HTTP in unit tests and verify the generated JSON. Check that the channel, message, colour, and optional metadata are present.

Run a staging deployment with an intentionally invalid Slack URL only after confirming that the plugin’s error policy is correct. The deployment should either continue with a warning or stop according to an explicit setting. Test all three event paths, because failure hooks can behave differently when an earlier Capistrano task aborts.

Manual testing can reveal integration issues that unit tests miss, such as a plugin not being loaded by the Capfile or a stage value being unavailable at a particular hook. Keep a test channel separate from the channel used by the wider team, especially when several engineers are working remotely from Brisbane, Adelaide, or regional offices.

It is useful to keep troubleshooting notes alongside the code. The same habit applies to unrelated development issues, such as recording experiments in Cocoa tracking-area notes, because a short explanation of the failed approach can save time when the problem returns months later.

Package the code as a reusable gem

Once the plugin is used by more than one application, move it into a Ruby gem. A gem can expose a Railtie-like Capistrano integration, provide sensible defaults, and make versioning independent of each application repository.

A minimal gem structure might contain:

capistrano-slack-notify/
├── lib/
│   ├── capistrano/
│   │   └── slack_notify.rb
│   └── capistrano-slack-notify.rb
├── capistrano-slack-notify.gemspec
└── README.md

Document supported Capistrano versions, required environment variables, hook behaviour, and whether Slack failures interrupt deployment. If the gem is shared across clients, allow channel names and message prefixes to be configured per application.

For a service that needs a more visible deployment history, the same plugin can send a link to a dashboard or release page. For example, a site such as the Bip Palace could use a dedicated deployment channel so content and engineering teams can distinguish a routine code release from a major public update.

Keep notifications useful over time

Slack deployment alerts work best when they remain predictable. Use consistent icons and wording, keep success messages short, and reserve urgent mentions for genuine production incidents. A channel that receives noisy messages for every local or review-app deployment will eventually be muted.

Separate staging and production channels when the team deploys frequently. Add a thread or release link for detailed information rather than placing logs in the main message. If a deploy is rolled back, send a separate rollback notification so the timeline cannot be mistaken for a successful release.

A Capistrano plugin is a small piece of automation, but it improves operational visibility across the whole team. Start with webhook-based status messages, test failure handling carefully, and add richer metadata only when it helps people make decisions. Put the plugin into your deployment repository, connect it to a test channel, and make the next release visible from the moment it starts.


cat ~/interests.json

KeyValue
editorTerminal-first workflow
osMac OS X / Unix
vcsGit, distributed version control
deployCapistrano, cron automation
graphicsSVG, Adobe Illustrator troubleshooting
networkingIP validation, SSH, VPN

git log --oneline --reverse

2013-10-30

Solving SVG import issues in Adobe Illustrator CS6 and CC

When importing an SVG into Illustrator, the operation fails with an unknown error [CANT]. A workaround for this Adobe-side bug.

2013

Solving NDK build issues on OS X

Troubleshooting native development kit compilation problems on Mac OS X.

2013

Programmatically adding PHP generated TypoScript to the backend configuration

Integrating dynamically generated TypoScript into Typo3 backend setups using PHP.

2013

ArgumentError: Could not parse PKey: no start line

Debugging an SSH key parsing error encountered during deployment.

2011-08-04

Validating IP-Addresses in PHP

Using PHP filter functions with flags like FILTER_FLAG_IPV4 and FILTER_FLAG_IPV6, and understanding how filter_var handles reserved IP addresses.

2011-07-09

Cocoa: Using NSTrackingArea

A short tutorial on using Cocoa's NSTrackingArea to capture mouseEntered and mouseExited events.


cat ~/contact.txt

github: github.com/x3ro
stackoverflow: x3ro
coderwall: coderwall.com/x3ro
twitter: @x3rames