lib/hudson/job_config_builder.rb in hudson-0.3.0.beta.11 vs lib/hudson/job_config_builder.rb in hudson-0.3.0.beta.12
- old
+ new
@@ -3,18 +3,19 @@
module Hudson
class JobConfigBuilder
attr_accessor :scm, :git_branches
attr_accessor :job_type, :matrix_project
attr_accessor :assigned_node
-
+
+ InvalidTemplate = Class.new(StandardError)
+
def initialize(options = nil, &block)
- if options.is_a?(Symbol)
+ if options.is_a?(String) || options.is_a?(Symbol)
@job_type = options.to_s
elsif options.is_a?(Hash)
@job_type = options[:job_type].to_s
end
- @matrix_project = %w[rubygem].include? job_type
yield self
@git_branches ||= ["**"]
end
def builder
@@ -30,23 +31,27 @@
b.canRoam !assigned_node
b.disabled false
b.blockBuildWhenUpstreamBuilding false
# build_triggers b
b.concurrentBuild false
- build_axes b if matrix_project
+ build_axes b if matrix_project?
build_steps b
b.publishers
b.buildWrappers
- b.runSequentially false if matrix_project
+ b.runSequentially false if matrix_project?
end
end
def to_xml
builder.to_s
end
protected
+
+ def matrix_project?
+ %w[ruby].include? job_type
+ end
# <scm class="hudson.plugins.git.GitSCM"> ... </scm>
def build_scm(b)
if scm && scm =~ /git/
b.scm :class => "hudson.plugins.git.GitSCM" do
@@ -110,14 +115,18 @@
end
def build_axes(b)
b.axes
end
-
+
+ # TODO modularise this
+ # TODO how to customize? e.g. EngineYard template?
+ VALID_JOB_TEMPLATES = %w[rails rails3 ruby rubygem]
def build_steps(b)
b.builders do
- if job_type == "rails"
+ raise InvalidTemplate unless VALID_JOB_TEMPLATES.include?(job_type)
+ if job_type == "rails3"
build_shell_step b, "bundle install"
build_ruby_step b, <<-RUBY.gsub(/^ /, '')
unless File.exist?("config/database.yml")
require 'fileutils'
example = Dir["config/database*"].first
@@ -125,11 +134,15 @@
FileUtils.cp example, "config/database.yml"
end
RUBY
build_shell_step b, "bundle exec rake db:schema:load"
build_shell_step b, "bundle exec rake"
+ elsif job_type == "ruby"
+ build_shell_step b, "bundle install"
+ build_shell_step b, "bundle exec rake"
elsif job_type == "rubygem"
- build_rake_step b, "features"
+ build_shell_step b, "bundle install"
+ build_shell_step b, "bundle exec rake"
end
end
end
# <hudson.tasks.Shell>
\ No newline at end of file