Sha256: 628b58cdbcb0ab772ce65be1fcad257153aca20eb039778edd8c2a25d5fc2d08

Contents?: true

Size: 1.42 KB

Versions: 2

Compression:

Stored size: 1.42 KB

Contents

ALLOWED_ENV_SETTINGS = %w{BUGSNAG_RELEASE_STAGE BUGSNAG_REPOSITORY BUGSNAG_REVISION BUGSNAG_BRANCH BUGSNAG_API_KEY BUGSNAG_APP_VERSION}
namespace :bugsnag do
  desc "Notify Bugsnag that new production code has been deployed"
  task :deploy do
    on :primary, reject: ->(h) { h.properties.no_release }, on_error: :continue do
      # Build the rake command
      rake         = fetch(:rake, "rake")
      rails_env    = fetch(:rails_env, "production")
      bugsnag_env  = fetch(:bugsnag_env, rails_env)
      rake_command = "cd '#{current_path}' && RAILS_ENV=#{rails_env} #{rake} bugsnag:deploy"

      # Build the new environment to pass through to rake
      new_env = {
        "BUGSNAG_RELEASE_STAGE" => bugsnag_env,
        "BUGSNAG_REVISION"      => fetch(:current_revision, nil),
        "BUGSNAG_REPOSITORY"    => fetch(:repository, nil),
        "BUGSNAG_BRANCH"        => fetch(:branch, nil),
        "BUGSNAG_API_KEY"       => fetch(:bugsnag_api_key, nil)
      }.reject { |_, v| v.nil? }

      # Pass through any existing env variables
      ALLOWED_ENV_SETTINGS.each { |opt| new_env[opt] = ENV[opt] if ENV[opt] }

      # Append the env to the rake command
      rake_command << " #{new_env.map{|k,v| "#{k}=#{v}"}.join(" ")}"

      # Run the rake command (only on one server)
      run(rake_command, :once => true)

      logger.info "Bugsnag deploy notification complete."
    end

    after "deploy", "bugsnag:deploy"
  end
end
# vi:ft=ruby

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
bugsnag-1.8.4 lib/bugsnag/tasks/bugsnag.cap
bugsnag-1.8.3 lib/bugsnag/tasks/bugsnag.cap