lib/hudson/job_config_builder.rb in hudson-0.3.0.beta.14 vs lib/hudson/job_config_builder.rb in hudson-0.3.0.beta.15
- old
+ new
@@ -1,21 +1,26 @@
require "builder"
module Hudson
class JobConfigBuilder
- attr_accessor :scm, :git_branches, :public_scm
attr_accessor :job_type, :matrix_project
+ attr_accessor :steps
+ attr_accessor :scm, :public_scm, :git_branches, :git_tool
attr_accessor :assigned_node
InvalidTemplate = Class.new(StandardError)
- def initialize(options = nil, &block)
- if options.is_a?(String) || options.is_a?(Symbol)
- self.job_type = options.to_s
- elsif options.is_a?(Hash)
- self.job_type = options[:job_type].to_s
- end
+ # +job_type+ - template of default steps to create with the job
+ # +steps+ - array of [:method, cmd], e.g. [:build_shell_step, "bundle initial"]
+ # - Default is based on +job_type+.
+ # +scm+ - URL to the repository. Currently only support git URLs.
+ # +public_scm+ - convert the +scm+ URL to a publicly accessible URL for the Hudson job config.
+ # +git_branches+ - array of branches to run builds. Default: ['master']
+ # +git_tool+ - key reference for Hudson CI git command. Default: 'Default'
+ # +assigned_node+ - restrict this job to running on slaves with these labels (space separated)
+ def initialize(job_type = :ruby, &block)
+ self.job_type = job_type.to_s if job_type
yield self
self.git_branches ||= ["master"]
end
@@ -93,11 +98,11 @@
b.doGenerateSubmoduleConfigurations false
b.authorOrCommitter false
b.clean false
b.wipeOutWorkspace false
b.buildChooser :class => "hudson.plugins.git.util.DefaultBuildChooser"
- b.gitTool "Default"
+ b.gitTool git_tool ? git_tool : "Default"
b.submoduleCfg :class => "list"
b.relativeTargetDir
b.excludedRegions
b.excludedUsers
end
@@ -126,25 +131,32 @@
# 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
- raise InvalidTemplate unless VALID_JOB_TEMPLATES.include?(job_type)
- if job_type == "rails" || 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
- puts "Using \#{example} for config/database.yml"
- FileUtils.cp example, "config/database.yml"
+ if job_type
+ raise InvalidTemplate unless VALID_JOB_TEMPLATES.include?(job_type)
+ if job_type == "rails" || 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
+ puts "Using \#{example} for config/database.yml"
+ 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"
+ else
+ build_shell_step b, "bundle install"
+ build_shell_step b, "bundle exec rake"
end
- RUBY
- build_shell_step b, "bundle exec rake db:schema:load"
- build_shell_step b, "bundle exec rake"
else
- build_shell_step b, "bundle install"
- build_shell_step b, "bundle exec rake"
+ steps.each do |step|
+ method, cmd = step
+ send(method.to_sym, b, cmd)
+ end
end
end
end
# <hudson.tasks.Shell>
\ No newline at end of file