Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ set :slack_room, "#general" # the room to send the message to
set :slack_subdomain, "example" # if your subdomain is example.slack.com

# optional
set :slack_webhook_url, "https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX" # overides the specified token and subdomain to use the specified webhook url.
set :slack_application, "Application Name" # override Capistrano `application`
set :slack_username, "Deploy Bot" # displayed as name of message sender
set :slack_emoji, ":cloud:" # will be used as the avatar for the message
Expand Down
10 changes: 7 additions & 3 deletions lib/capistrano/slack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def self.extended(configuration)
namespace :slack do

task :starting do
return if slack_token.nil?
return if slack_token.nil? and slack_webhook_url.nil?

announcement = "#{announced_deployer} is deploying #{announced_application_name} to #{announced_stage}"

Expand All @@ -31,7 +31,7 @@ def self.extended(configuration)
end

task :finished do
return if slack_token.nil?
return if slack_token.nil? and slack_webhook_url.nil?
end_time = Time.now
start_time = fetch(:start_time)
elapsed = end_time.to_i - start_time.to_i
Expand Down Expand Up @@ -68,7 +68,11 @@ def branch

def post_slack_message(message, attachments=[])
# Parse the API url and create an SSL connection
uri = URI.parse("https://#{slack_subdomain}.slack.com/services/hooks/incoming-webhook?token=#{slack_token}")
if slack_webhook_url.nil?
uri = URI.parse("https://#{slack_subdomain}.slack.com/services/hooks/incoming-webhook?token=#{slack_token}")
else
uri = URI.parse(slack_webhook_url)
end
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
Expand Down