Skip to content

Commit

Permalink
added EmailReporter plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Rehfeld committed Sep 17, 2008
0 parents commit 79240f3
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
5 changes: 5 additions & 0 deletions README.markdown
@@ -0,0 +1,5 @@
cruisecontrol.rb-plugins
========================

A place for my cruisecontrol.rb plugin(s): So far the short list consists of:
* EmailReporter (will mail a build report after every build -- as opposed to standard EmailNotifier, which will only report state changes (build broken/fixed)
61 changes: 61 additions & 0 deletions builder_plugins/email_reporter.rb
@@ -0,0 +1,61 @@
# Put this file into your CRUISE_DATA_ROOT/builder_plugins directory to enable
# ----------------------------------------------------------------------------
#
# CruiseControl.rb can send email reports on every build. To make it happen, you need to tell it how
# to send email, and who to send it to. Do the following:
#
# 1. Configure SMTP server connection. Open <em>[cruise&nbsp;data]</em>/config/site_config.rb,
# read the comments in it and edit according to your situation.
#
# 2. Tell the builder, whom do you want to receive build notices:
# <pre><code>Project.configure do |project|
# ...
# project.email_reporter.emails = ['john@doe.com', 'jane@doe.com']
# ...
# end</code></pre>
#
# You can also specify who to send the email from, either for the entire site by setting Configuration.email_from
# in <em>[cruise&nbsp;data]</em>/config/site_config.rb, or on a per project basis, by placing the following line in cruise_config.rb:
# <pre><code>Project.configure do |project|
# ...
# project.email_reporter.from = "cruisecontrol@doe.com"
# ...
# end</code></pre>
#
# The emails from CruiseControl.rb can have a lot of details about the build, or just a link to the build page in the dashboard.
# Usually, you will want the latter. Set the dashboard URL in the <em>[cruise&nbsp;data]</em>/config/site_config.rb as follows:
#
# <pre><code>Configuration.dashboard_url = 'http://your.host.name.com:3333'</pre></code>

class EmailReporter
attr_accessor :emails
attr_writer :from

def initialize(project = nil)
@emails = []
end

def from
@from || Configuration.email_from
end

def build_finished(build)
return if @emails.empty?
email :deliver_build_report, build, "#{build.project.name} build #{build.label} #{build.failed? ? 'failed' : 'succeded'}", "The build #{build.failed? ? 'failed' : 'succeded'}."
end

private

def email(template, build, *args)
BuildMailer.send(template, build, @emails, from, *args)
CruiseControl::Log.event("Sent e-mail to #{@emails.size == 1 ? "1 person" : "#{@emails.size} people"}", :debug)
rescue => e
settings = ActionMailer::Base.smtp_settings.map { |k,v| " #{k.inspect} = #{v.inspect}" }.join("\n")
CruiseControl::Log.event("Error sending e-mail - current server settings are :\n#{settings}", :error)
raise
end

end

Project.plugin :email_reporter

0 comments on commit 79240f3

Please sign in to comment.