Created
February 18, 2015 18:15
-
-
Save davestevens/fd730b8211c2db751a11 to your computer and use it in GitHub Desktop.
Capistrano Slack integration.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Capistrano Task that hooks into `deploy:finished` to send a message to Slack | |
# | |
# 1. Setup a Slack Incoming Webhook Integration (https://api.slack.com/incoming-webhooks) | |
# 2. Put the Webhook URL in an Environment variable (SLACK_WEBHOOK_URL) | |
# 3. Place this file in `lib/capistrano/tasks` | |
# | |
# This will then create a new message in the channel on deployment, including who, what and where information | |
require "net/http" | |
require "json" | |
require "uri" | |
namespace :slack_notify do | |
desc "Notify Slack of a deployment" | |
task :deployed do | |
url = ENV["SLACK_WEBHOOK_URL"] | |
user = `git config user.name`.chomp | |
branch = fetch(:branch) | |
tag = `git describe --abbrev=0 --tags`.chomp | |
stage = fetch(:stage) | |
payload = { | |
"username": fetch(:application), | |
"text": "#{user} deployed branch #{branch} (#{tag}) to #{stage}.", | |
"icon_url": "https://avatars2.githubusercontent.com/u/58257?v=3&s=40" | |
}.to_json | |
Net::HTTP.post_form(URI.parse(url), payload: payload) | |
end | |
end | |
namespace :deploy do | |
after :finished, "slack_notify:deployed" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment