Skip to content

Instantly share code, notes, and snippets.

Forked from nosolopau/deploy.rb
Created May 15, 2020 19:22
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Send email notifications after deploy (with Capistrano and Rails 4). Capistrano variables reference:
# Add the following lines at the end of config/deploy.rb
Dir["config/deploy/extras/*.rb"].each { |file| load file }
set :notify_emails, [""]
after "deploy", "deploy:notify"
# config/deploy/extras/notifier.rb
require 'action_mailer'
ActionMailer::Base.delivery_method = :sendmail # You can also use :smtp...
ActionMailer::Base.raise_delivery_errors = true
class Notifier < ActionMailer::Base
default from: '"notifier" <>'
def deploy_notification(cap_vars)
application_name = cap_vars.application.split('_')[0]
mail(:to => cap_vars.notify_emails, :subject => "Application #{application_name} has been deployed in #{cap_vars.stage}") do |format|
format.text do
render :text => "Hi,\n\nThe application #{application_name} has been deployed in the #{cap_vars.stage} platform.\n\n#{cap_vars.release_notes}"
namespace :deploy do
desc "Email notifier"
task :notify, :roles => :app, :except => { :no_release => true } do
git_commits_range = "#{previous_revision.strip}..#{current_revision.strip}"
git_log = `git log --pretty=oneline --abbrev-commit #{git_commits_range}`
set :release_notes, git_log.blank? ? "No changes since last deploy." : "Last changes:\n" + git_log
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment