Class: JenkinsJob::Deployer
- Inherits:
-
Object
- Object
- JenkinsJob::Deployer
- Defined in:
- lib/rubyjobbuilderdsl/deployer.rb
Instance Method Summary collapse
- #deploy(&block) ⇒ Object
- #each(&block) ⇒ Object
- #generate_xml ⇒ Object
-
#initialize(*builder) ⇒ Deployer
constructor
A new instance of Deployer.
- #run(&block) ⇒ Object
- #usage ⇒ Object
Constructor Details
#initialize(*builder) ⇒ Deployer
Returns a new instance of Deployer.
5 6 7 |
# File 'lib/rubyjobbuilderdsl/deployer.rb', line 5 def initialize(*builder) @builders = builder end |
Instance Method Details
#deploy(&block) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/rubyjobbuilderdsl/deployer.rb', line 30 def deploy(&block) config_file = ARGV.find { |z| z =~ /--config-file=/ }.to_s.split('=')[1] usage unless config_file config = {} File.read(config_file).each_line do |line| if line =~ /\S+\=\S+/ key, val = line.split('=') config[key] = val.chomp end end client = JenkinsClient.new(config['url'], config['user'], config['password']) deployer = self client.instance_eval do @deployer = deployer def each(&block) @deployer.each(&block) end end unless block block = proc do each do |name, xml, type| upload_job(name, xml) if type == :job upload_view(name, xml) if type == :view end end end client.instance_eval(&block) end |
#each(&block) ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/rubyjobbuilderdsl/deployer.rb', line 9 def each(&block) @builders.each do |b| b.generate_xml do |name, xml, type| yield name, xml, type if block end end end |
#generate_xml ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/rubyjobbuilderdsl/deployer.rb', line 17 def generate_xml outputdir = ARGV.find { |z| z =~ /--output-dir=/ }.to_s.split('=')[1] usage unless outputdir each do |name, xml, type| path = "#{outputdir}/#{name}.xml" $stdout.puts "creating #{type} #{path}" File.open(path, 'w+') do |f| f.write(xml) end end end |
#run(&block) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/rubyjobbuilderdsl/deployer.rb', line 78 def run(&block) xml = ARGV.find { |a| a == '--xml' } deploy = ARGV.find { |a| a == '--deploy' } if xml generate_xml exit 0 end if deploy deploy(&block) exit 0 end usage end |
#usage ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/rubyjobbuilderdsl/deployer.rb', line 63 def usage $stderr.puts("Usage:\n\nruby \#{File.basename($PROGRAM_NAME)} --xml --output-dir=.|--deploy --config-file=config/localhost.ini]\n\nExample:\n\nruby \#{File.basename($PROGRAM_NAME)} --xml --output-dir=.\nruby \#{File.basename($PROGRAM_NAME)} --deploy --config-file=config/localhost.ini\n" ) exit 1 end |