Skip to content

Instantly share code, notes, and snippets.

@nickveys
Forked from pablopaul/deploy.rb
Last active February 27, 2018 18:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nickveys/7005c5e59e187726454c0626db5f176e to your computer and use it in GitHub Desktop.
Save nickveys/7005c5e59e187726454c0626db5f176e to your computer and use it in GitHub Desktop.
Notify Sentry of a new release via Capistrano with webhook
# This task will notify Sentry via webhook that you have deployed
# a new release. It uses the release timestamp as the `version`
# (like 20151113182847) and the git ref as the optional `ref` value.
#
# This task requires `:sentry_uri` to be set. This can be done in
# a site-specific config/deploy/xxx.rb file. This can be obtained from
# the project's settings page.
# For Rails app, this goes in config/deploy.rb
namespace :sentry do
task :notify do
run_locally do
require 'uri'
require 'net/https'
require 'json'
uri = URI.parse(fetch(:sentry_uri))
req = Net::HTTP::Post.new(uri.request_uri)
params = {
version: fetch(:release_timestamp),
ref: fetch(:current_revision),
}
req.body = ::JSON.dump(params)
response = Net::HTTP.start(uri.host, uri.port, use_ssl: true) { |h| h.request(req) }
end
end
end
# If you want deployments to be published in every Rails environment, put this
# in config/deploy.rb, otherwise put it your environment-specific deploy file
# i.e. config/deploy/production.rb
after 'deploy:published', 'sentry:notify'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment