class Jenkins::JobDSL
Constants
- MULTIPLE
Attributes
jobs[RW]
current_prefix[RW]
current_scope[RW]
jobs[RW]
name[RW]
Public Class Methods
new(options = {})
click to toggle source
# File lib/dynport_tools/job_dsl.rb, line 18 def initialize(options = {}) options.each do |key, value| self.send(:"#{key}=", value) if self.respond_to?(:"#{key}=") end self.jobs = [] self.current_scope = {} end
setup(namespace = :default, &block)
click to toggle source
# File lib/dynport_tools/job_dsl.rb, line 6 def setup(namespace = :default, &block) dsl = self.new dsl.instance_eval(&block) if block_given? self.jobs ||= {} self.jobs[namespace] ||= Array.new self.jobs[namespace] += dsl.jobs self.jobs[namespace] end
Public Instance Methods
command_with_env(cmd, env = {})
click to toggle source
# File lib/dynport_tools/job_dsl.rb, line 79 def command_with_env(cmd, env = {}) ((env || {}).sort.map { |key, value| "#{key}=#{value}" } + [@bundle_exec ? "bundle exec" : nil, cmd].compact).join(" ") end
disabled!(&block)
click to toggle source
# File lib/dynport_tools/job_dsl.rb, line 44 def disabled!(&block) disabled(true, &block) end
job(name, &block)
click to toggle source
# File lib/dynport_tools/job_dsl.rb, line 104 def job(name, &block) if current_prefix @prefix_indexes ||= Hash.new(0) name = "#{current_prefix}%03d %s" % [@prefix_indexes[current_prefix] += 1, name] end job = JobDSL.new(self.current_scope.merge(:name => name)) job.instance_eval(&block) if block_given? self.jobs << job end
rails_command(cmd, options = {})
click to toggle source
# File lib/dynport_tools/job_dsl.rb, line 56 def rails_command(cmd, options = {}) rails_command_or_script(%("#{cmd.gsub('"', '\\"')}"), options) end
rails_command_or_script(cmd_or_script, options = {})
click to toggle source
# File lib/dynport_tools/job_dsl.rb, line 69 def rails_command_or_script(cmd_or_script, options = {}) raise "rails_root must be set" if rails_root.nil? command %(cd #{rails_root} && #{command_with_env(runner_command(options[:rails_env]), options[:env])} #{cmd_or_script}) end
rails_script(*args)
click to toggle source
# File lib/dynport_tools/job_dsl.rb, line 60 def rails_script(*args) rails_command_or_script(*args) end
rake_task(task, options = {})
click to toggle source
# File lib/dynport_tools/job_dsl.rb, line 64 def rake_task(task, options = {}) options[:env] = (options[:env] || {}).merge("RAILS_ENV" => options[:rails_env]) if options[:rails_env] command "cd #{rails_root} && " + command_with_env("rake #{task}", options[:env]) end
runner_command(env = nil)
click to toggle source
# File lib/dynport_tools/job_dsl.rb, line 74 def runner_command(env = nil) env ||= rails_env [@rails3 ? "rails runner" : "./script/runner", env ? "-e #{env}" : nil].compact.join(" ") end
setter_or_getter(key, *values, &block)
click to toggle source
# File lib/dynport_tools/job_dsl.rb, line 94 def setter_or_getter(key, *values, &block) value = MULTIPLE.include?(key) ? values : values.first if block_given? with(key => value, &block) elsif ![[], nil].include?(value) self.send(:"#{key}=", value) end self.instance_variable_get("@#{key}") end
use_bundle_exec!()
click to toggle source
# File lib/dynport_tools/job_dsl.rb, line 52 def use_bundle_exec! @bundle_exec = true end
use_rails3!()
click to toggle source
# File lib/dynport_tools/job_dsl.rb, line 48 def use_rails3! @rails3 = true end
with(options, &block)
click to toggle source
# File lib/dynport_tools/job_dsl.rb, line 83 def with(options, &block) old_scope = self.current_scope self.current_scope = self.current_scope.merge(options) self.instance_eval(&block) self.current_scope = old_scope end