Code Monkey home page Code Monkey logo

capistrano-slackify's Introduction

Capistrano Slackify Build Status Code Climate Gem Version

Publish deploy notifications to Slack - for Capistrano v3.

Installation

Add this line to your application's Gemfile:

gem 'capistrano-slackify', require: false

And then execute:

$ bundle

Or install it yourself as:

$ gem install capistrano-slackify

Usage

Require the gem in your Capfile:

require 'capistrano/slackify'

And then set the required variables in config/deploy.rb:

set :slack_url, 'https://hooks.slack.com/services/your/webhook/url'

Ensure that you have enabled the incoming webhooks integration - copy/paste the webhook url provided in the setup instructions.

The task will run automatically on deploy. Alternatively, you can notify of a deploy starting manually by using:

bundle exec cap production slack:notify_started

Or to notify of a finished deploy:

bundle exec cap production slack:notify_finished

By default, this will publish something along the lines of:

Revision 64a3c1de of my_app deployed to production by seenmyfate in 333 seconds.

If a deploy has failed, the following message will be published by default:

production deploy of my_app with revision/branch 64a3c1de failed

As with the other tasks, it is also possible to notify failures manually:

bundle exec cap production slack:notify_failed

Customisation

Any of the defaults can be over-ridden in config/deploy.rb:

set :slack_channel, ['#devops', '#other-channel']
set :slack_username, 'Deploybot'
set :slack_emoji, ':trollface:'
set :slack_user, ENV['GIT_AUTHOR_NAME']
set :slack_fields, ['status', 'stage', 'branch', 'revision', 'hosts']
set :slack_mrkdwn_in, ['pretext', 'text', 'fields']
set :slack_hosts, -> { release_roles(:all).map(&:hostname).join("\n") }
set :slack_text, -> {
  elapsed = Integer(fetch(:time_finished) - fetch(:time_started))
  "Revision #{fetch(:current_revision, fetch(:branch))} of " \
  "#{fetch(:application)} deployed to #{fetch(:stage)} by #{fetch(:slack_user)} " \
  "in #{elapsed} seconds."
}
set :slack_deploy_starting_text, -> {
  "#{fetch(:stage)} deploy starting with revision/branch #{fetch(:current_revision, fetch(:branch))} for #{fetch(:application)}"
}
set :slack_deploy_failed_text, -> {
  "#{fetch(:stage)} deploy of #{fetch(:application)} with revision/branch #{fetch(:current_revision, fetch(:branch))} failed"
}
set :slack_deploy_finished_color, 'good'
set :slack_deploy_failed_color, 'danger'
set :slack_notify_events, [:started, :finished, :failed]

You can setup custom fields by defining a mapping for how to display them in slack:

set :slack_fields, ['status', 'environment', 'docker_image']
# You could also add your custom mappings to the defaults with:
# set :slack_fields, fetch(:slack_fields).push('environment', 'docker_image')
set :slack_custom_field_mapping, -> {
  {
    'environment' => {
      title: 'Environment',
      value: -> {
        if fetch(:stage) == :production
          'production'
        else
          "staging-#{fetch(:staging_name)}"
        end
      },
      short: true,
    },
    'docker_image' => {
      title: 'Docker image',
      value: fetch(:docker_image),
      short: false,
    },
  }
}

To configure the way slack parses your message (see 'Parsing Modes' at https://api.slack.com/docs/formatting) use the :slack_parse setting:

set :slack_parse, 'none' # available options: 'none', 'full'

Copyright

Copyright (c) 2014 OnTheBeach Ltd. See LICENSE.txt for further details.

capistrano-slackify's People

Contributors

bew avatar carljohnstone avatar cheald avatar deanopound avatar hfm avatar jamescotterill avatar jdks avatar korotovsky avatar mekajiki avatar mikespokefire avatar notgary avatar onigra avatar paulingham avatar seenmyfate avatar sija avatar spk avatar sporkd avatar takeshiyako2 avatar underscorebrody avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

capistrano-slackify's Issues

request: report failures

I would be grateful if slackify could report failures to the channel as well. Something as simple as,

Deployment of {app} to {env} of {branch/revision} failed.

Deploy from windows

Hi guys,
When i'm deploy from mac everything OK, but from Windows:

cap aborted!
NoMethodError: undefined method `name' for nil:NilClass

Tasks: TOP => deploy:starting => slack:notify_started
(See full trace by running task with --trace)
The deploy has failed with an error: undefined method name' for nil:NilClass C:/Ruby193/lib/ruby/gems/1.9.1/gems/sshkit-1.7.1/lib/sshkit/host.rb:29:ininitialize': undefined method name' for nil:NilClass (NoMethodError) from C:/Ruby193/lib/ruby/gems/1.9.1/gems/sshkit-1.7.1/lib/sshkit/backends/local.rb:10:innew'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/sshkit-1.7.1/lib/sshkit/backends/local.rb:10:in initialize' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/capistrano-3.4.0/lib/capistrano/dsl.rb:59:innew'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/capistrano-3.4.0/lib/capistrano/dsl.rb:59:in run_locally' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/capistrano-slackify-2.2.0/lib/capistrano/tasks/slackify.cap:31:inblock (2 levels) in <top (required)>'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.4.2/lib/rake/task.rb:240:in call' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.4.2/lib/rake/task.rb:240:inblock in execute'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.4.2/lib/rake/task.rb:235:in each' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.4.2/lib/rake/task.rb:235:inexecute'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.4.2/lib/rake/task.rb:179:in block in invoke_with_call_chain' from C:/Ruby193/lib/ruby/1.9.1/monitor.rb:211:inmon_synchronize'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.4.2/lib/rake/task.rb:172:in invoke_with_call_chain' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.4.2/lib/rake/task.rb:165:ininvoke'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/capistrano-3.4.0/lib/capistrano/dsl/task_enhancements.rb:14:in block in after' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.4.2/lib/rake/task.rb:240:incall'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.4.2/lib/rake/task.rb:240:in block in execute' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.4.2/lib/rake/task.rb:235:ineach'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.4.2/lib/rake/task.rb:235:in execute' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.4.2/lib/rake/task.rb:179:inblock in invoke_with_call_chain'
from C:/Ruby193/lib/ruby/1.9.1/monitor.rb:211:in mon_synchronize' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.4.2/lib/rake/task.rb:172:ininvoke_with_call_chain'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.4.2/lib/rake/task.rb:165:in invoke' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/capistrano-3.4.0/lib/capistrano/dsl.rb:16:ininvoke'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/capistrano-3.4.0/lib/capistrano/dsl/task_enhancements.rb:57:in exit_deploy_because_of_exception' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/capistrano-3.4.0/lib/capistrano/application.rb:78:inexit_because_of_exception'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.4.2/lib/rake/application.rb:186:in rescue in standard_exception_handling' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.4.2/lib/rake/application.rb:176:instandard_exception_handling'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.4.2/lib/rake/application.rb:75:in run' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/capistrano-3.4.0/lib/capistrano/application.rb:15:inrun'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/capistrano-3.4.0/bin/cap:3:in <top (required)>' from C:/Ruby193/bin/cap:23:inload'
from C:/Ruby193/bin/cap:23:in `

'

slack_parse should be none

Please change slack_parse default value. It's should be 'none' or 'all', slack can't parse 'default' value.

Send notify on more channels

Is it possible to send the notification on multiple channels? Yes? how?
I tried to set
set :slack_channel, '#bot-all,#product-bot'
or
set :slack_channel, '#bot-all #product-bot'
but not work!

thank you

Broken running rails console or starting up the rails server.

Installed the gem and deploy works like a charm. However, when I try to open up rails console or rails server, I got this error:

/Users/jchung/.rvm/gems/[email protected]/gems/capistrano-slackify-2.0.0/lib/capistrano/tasks/slackify.cap:1:in <top (required)>': undefined methodnamespace' for main:Object (NoMethodError)
from /Users/jchung/.rvm/gems/[email protected]/gems/activesupport-4.1.5/lib/active_support/dependencies.rb:241:in load' from /Users/jchung/.rvm/gems/[email protected]/gems/activesupport-4.1.5/lib/active_support/dependencies.rb:241:inblock in load'
from /Users/jchung/.rvm/gems/[email protected]/gems/activesupport-4.1.5/lib/active_support/dependencies.rb:232:in load_dependency' from /Users/jchung/.rvm/gems/[email protected]/gems/activesupport-4.1.5/lib/active_support/dependencies.rb:241:inload'
from /Users/jchung/.rvm/gems/[email protected]/gems/capistrano-slackify-2.0.0/lib/capistrano/slackify.rb:2:in <top (required)>' from /Users/jchung/.rvm/gems/ruby-2.1.2@global/gems/bundler-1.6.3/lib/bundler/runtime.rb:85:inrequire'
from /Users/jchung/.rvm/gems/ruby-2.1.2@global/gems/bundler-1.6.3/lib/bundler/runtime.rb:85:in rescue in block in require' from /Users/jchung/.rvm/gems/ruby-2.1.2@global/gems/bundler-1.6.3/lib/bundler/runtime.rb:68:inblock in require'
from /Users/jchung/.rvm/gems/ruby-2.1.2@global/gems/bundler-1.6.3/lib/bundler/runtime.rb:61:in each' from /Users/jchung/.rvm/gems/ruby-2.1.2@global/gems/bundler-1.6.3/lib/bundler/runtime.rb:61:inrequire'
from /Users/jchung/.rvm/gems/ruby-2.1.2@global/gems/bundler-1.6.3/lib/bundler.rb:132:in require' from /Users/jchung/projects/collabnet/cloudforge/config/application.rb:10:in<top (required)>'
from /Users/jchung/.rvm/gems/[email protected]/gems/railties-4.1.5/lib/rails/commands/commands_tasks.rb:146:in require' from /Users/jchung/.rvm/gems/[email protected]/gems/railties-4.1.5/lib/rails/commands/commands_tasks.rb:146:inrequire_application_and_environment!'
from /Users/jchung/.rvm/gems/[email protected]/gems/railties-4.1.5/lib/rails/commands/commands_tasks.rb:68:in console' from /Users/jchung/.rvm/gems/[email protected]/gems/railties-4.1.5/lib/rails/commands/commands_tasks.rb:40:inrun_command!'
from /Users/jchung/.rvm/gems/[email protected]/gems/railties-4.1.5/lib/rails/commands.rb:17:in <top (required)>' from bin/rails:4:inrequire'
from bin/rails:4:in `

'

Any clue?

local_user is nil in CircleCI

Hi!
I used capistrano-slackify in CircleCI 2.0, and encountered below error.

00:00 slack:notify_failed
      Notifying Slack of deploy failed
bundler: failed to load command: cap (/home/circleci/repo/vendor/bundle/ruby/2.4.0/bin/cap)
NoMethodError: undefined method `strip' for nil:NilClass

https://github.com/onthebeach/capistrano-slackify/blob/master/lib/capistrano/tasks/slackify.cap#L64

In CircleCI, local_user is nil.
So, I added Environment Variable USER in CircleCI. But it was difficult to notice this cause.

I am thinking of a pull request like below,

capistrano-slackify/lib/capistrano/tasks/slackify.cap

- set :slack_user, -> { local_user.strip }
+ set :slack_user, -> { local_user.to_s.strip }

what do you think about it? Please tell me any other good ideas.
Thanks!

Don't know how to build task 'slack:notify'

Hi,

Looks like an awesome gem! However, got this error when trying to run it:

$ bundle exec cap staging slack:notify
rvm 1.25.31 (stable) by Wayne E. Seguin <[email protected]>, Michal Papis <[email protected]> [https://rvm.io/]
ruby-2.1.3
ruby 2.1.3p242 (2014-09-19 revision 47630) [x86_64-linux]
cap aborted!
Don't know how to build task 'slack:notify'
...

Added gem 'capistrano-slackify' to Gemfile, bundleed and added require 'capistrano/slackify' to Capfile.

Anything I missed?

deploy:rollback error

$ ruby -v
ruby 2.0.0p353 (2013-11-22 revision 43784) [x86_64-linux]

$ cap --version
Capistrano Version: 3.2.1 (Rake Version: 10.3.2)

$ gem list | grep capistrano-slackify
capistrano-slackify (1.1.0)
$ cap staging deploy:rollback --trace
** Invoke staging (first_time)
** Execute staging
** Invoke load:defaults (first_time)
** Execute load:defaults
** Invoke deploy:rollback (first_time)
** Execute deploy:rollback
** Invoke deploy:starting (first_time)
** Execute deploy:starting
** Invoke deploy:check (first_time)
** Execute deploy:check
** Invoke git:check (first_time)
** Invoke git:wrapper (first_time)
** Execute git:wrapper
INFO[7deb0542] Running /usr/bin/env mkdir -p /tmp/App/ on 111.222.111.222
DEBUG[7deb0542] Command: /usr/bin/env mkdir -p /tmp/App/
INFO[7deb0542] Finished in 0.073 seconds with exit status 0 (successful).
DEBUGUploading /tmp/App/git-ssh.sh 0.0%
INFOUploading /tmp/App/git-ssh.sh 100.0%
INFO[5d56c4f9] Running /usr/bin/env chmod +x /tmp/App/git-ssh.sh on 111.222.111.222
DEBUG[5d56c4f9] Command: /usr/bin/env chmod +x /tmp/App/git-ssh.sh
INFO[5d56c4f9] Finished in 0.009 seconds with exit status 0 (successful).
** Execute git:check
DEBUG[d0b84204] Running /usr/bin/env git ls-remote -h [email protected]:ore/App.git on 111.222.111.222
DEBUG[d0b84204] Command: ( GIT_ASKPASS=/bin/echo GIT_SSH=/tmp/App/git-ssh.sh /usr/bin/env git ls-remote -h [email protected]:ore/App.git )
DEBUG[d0b84204]     Error reading response length from authentication socket.
DEBUG[d0b84204]     c675ea2d2fcdcba8343f9dff0205588770e46f46    refs/heads/develop
DEBUG[d0b84204]     5152c40a82947f9c4f1a63e88549e43bc10c169d    refs/heads/master
DEBUG[d0b84204]     Error reading response length from authentication socket.
DEBUG[d0b84204] Finished in 2.582 seconds with exit status 0 (successful).
** Invoke deploy:check:directories (first_time)
** Execute deploy:check:directories
INFO[49e29ca6] Running /usr/bin/env mkdir -pv /home/ore/App/shared /home/ore/App/releases on 111.222.111.222
DEBUG[49e29ca6] Command: /usr/bin/env mkdir -pv /home/ore/App/shared /home/ore/App/releases
INFO[49e29ca6] Finished in 0.008 seconds with exit status 0 (successful).
** Invoke deploy:check:linked_dirs (first_time)
** Execute deploy:check:linked_dirs
INFO[18c4d937] Running /usr/bin/env mkdir -pv /home/ore/App/shared/log /home/ore/App/shared/data on 111.222.111.222
DEBUG[18c4d937] Command: /usr/bin/env mkdir -pv /home/ore/App/shared/log /home/ore/App/shared/data
INFO[18c4d937] Finished in 0.008 seconds with exit status 0 (successful).
** Invoke deploy:check:make_linked_dirs (first_time)
** Execute deploy:check:make_linked_dirs
** Invoke deploy:check:linked_files (first_time)
** Execute deploy:check:linked_files
** Invoke deploy:set_previous_revision (first_time)
** Execute deploy:set_previous_revision
DEBUG[8e890999] Running /usr/bin/env [ -f /home/ore/App/current/REVISION ] on 111.222.111.222
DEBUG[8e890999] Command: [ -f /home/ore/App/current/REVISION ]
DEBUG[8e890999] Finished in 0.009 seconds with exit status 0 (successful).
DEBUG[154997ec] Running /usr/bin/env cat /home/ore/App/current/REVISION 2>/dev/null on 111.222.111.222
DEBUG[154997ec] Command: /usr/bin/env cat /home/ore/App/current/REVISION 2>/dev/null
DEBUG[154997ec]     74cce5e
DEBUG[154997ec] Finished in 0.011 seconds with exit status 0 (successful).
** Invoke deploy:started (first_time)
** Execute deploy:started
** Invoke deploy:reverting (first_time)
** Execute deploy:reverting
** Invoke deploy:revert_release (first_time)
** Invoke deploy:rollback_release_path (first_time)
** Execute deploy:rollback_release_path
DEBUG[a7e7e1bd] Running /usr/bin/env ls -xr /home/ore/App/releases on 111.222.111.222
DEBUG[a7e7e1bd] Command: /usr/bin/env ls -xr /home/ore/App/releases
DEBUG[a7e7e1bd]     20140905025618
DEBUG[a7e7e1bd] Finished in 0.012 seconds with exit status 0 (successful).
ERRORThere are no older releases to rollback to
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing on host 111.222.111.222: exit
/usr/local/lib/ruby/gems/2.0.0/gems/capistrano-3.2.1/lib/capistrano/tasks/deploy.rake:195:in `exit'
/usr/local/lib/ruby/gems/2.0.0/gems/capistrano-3.2.1/lib/capistrano/tasks/deploy.rake:195:in `block (3 levels) in '
/usr/local/lib/ruby/gems/2.0.0/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:54:in `instance_exec'
/usr/local/lib/ruby/gems/2.0.0/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:54:in `run'
/usr/local/lib/ruby/gems/2.0.0/gems/sshkit-1.5.1/lib/sshkit/runners/parallel.rb:13:in `block (2 levels) in execute'
SystemExit: exit
/usr/local/lib/ruby/gems/2.0.0/gems/capistrano-3.2.1/lib/capistrano/tasks/deploy.rake:195:in `exit'
/usr/local/lib/ruby/gems/2.0.0/gems/capistrano-3.2.1/lib/capistrano/tasks/deploy.rake:195:in `block (3 levels) in '
/usr/local/lib/ruby/gems/2.0.0/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:54:in `instance_exec'
/usr/local/lib/ruby/gems/2.0.0/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:54:in `run'
/usr/local/lib/ruby/gems/2.0.0/gems/sshkit-1.5.1/lib/sshkit/runners/parallel.rb:13:in `block (2 levels) in execute'
Tasks: TOP => deploy:revert_release => deploy:rollback_release_path

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.