Class: LeeroyJenkins::Cli

Inherits:
Thor
  • Object
show all
Defined in:
lib/leeroy_jenkins/cli.rb

Instance Method Summary collapse

Instance Method Details

#backupObject



45
46
47
48
49
# File 'lib/leeroy_jenkins/cli.rb', line 45

def backup
  jenkins_client = build_jenkins_client options
  job_names_to_backup = JobFinder.new(options[:job_regex], jenkins_client).find_jobs
  JobBackupper.new(job_names_to_backup, jenkins_client, options[:backup_dir], options[:threads]).backup
end

#restoreObject



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/leeroy_jenkins/cli.rb', line 54

def restore
  jenkins_client = build_jenkins_client options
  job_restorer = JobRestorer.new jenkins_client, options[:backup_dir], options[:threads]
  result = options[:dry_run] ? job_restorer.dry_run : job_restorer.restore!

  if options[:dry_run]
    result.each do |key, value|
      puts "#{key}:"
      puts
      puts value
    end
  else
    result.each do |key, value|
      puts "#{key}: #{value}"
    end
  end
end

#update_configObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/leeroy_jenkins/cli.rb', line 16

def update_config
  raw_xml_string = File.read options[:new_xml]
  if error = LeeroyJenkins.invalid_xml_document?(raw_xml_string)
    error "#{options[:new_xml]}} is not well-formed XML: #{error}"
    exit 1
  end

  jenkins_client = build_jenkins_client options

  job_names_to_update = JobFinder.new(options[:job_regex], jenkins_client).find_jobs
  job_updater = JobUpdater.new job_names_to_update, raw_xml_string, jenkins_client, options[:xpath], options[:at_xpath], options[:threads]
  result = options[:dry_run] ? job_updater.dry_run : job_updater.update_jobs!

  if options[:dry_run]
    result.each do |key, value|
      puts "#{key}:"
      puts
      puts value
    end
  else
    result.each do |key, value|
      puts "#{key}: #{value}"
    end
  end
end