class LeeroyJenkins::JobRestorer
Attributes
backup_dir[R]
jenkins_client[R]
job_names[R]
job_regex[R]
threads[R]
Public Class Methods
new(jenkins_client, backup_dir, threads, job_names, job_regex)
click to toggle source
# File lib/leeroy_jenkins/job_restorer.rb, line 5 def initialize(jenkins_client, backup_dir, threads, job_names, job_regex) @jenkins_client = jenkins_client @backup_dir = backup_dir @threads = threads @job_names = job_names @job_regex = Regexp.new(job_regex) end
Public Instance Methods
dry_run()
click to toggle source
# File lib/leeroy_jenkins/job_restorer.rb, line 13 def dry_run pairs = Parallel.map(config_xml_file_paths, in_threads: threads) do |xml_path| job_name = File.basename(xml_path, '.*') [job_name, File.read(xml_path)] end Result.new(Hash[pairs]) end
restore!()
click to toggle source
# File lib/leeroy_jenkins/job_restorer.rb, line 22 def restore! pairs = Parallel.map(config_xml_file_paths, in_threads: threads) do |xml_path| job_name = File.basename(xml_path, '.*') http_status_code = jenkins_client.job.create_or_update( job_name, File.read(xml_path) ) [job_name, http_status_code] end Result.new(Hash[pairs]) end
Private Instance Methods
config_xml_file_paths()
click to toggle source
# File lib/leeroy_jenkins/job_restorer.rb, line 38 def config_xml_file_paths Dir.entries(backup_dir) .select { |file_name| file_name.end_with? '.xml' } .select { |file_name| restore_job?(file_name) } .map { |file_name| "#{backup_dir}/#{file_name}" } end
restore_job?(file_name)
click to toggle source
# File lib/leeroy_jenkins/job_restorer.rb, line 45 def restore_job?(file_name) # http://rubular.com/r/UxTupLRyg4 job_name = file_name.match(/^(?<job_name>[^.]+)\.xml$/)['job_name'] if job_names.any? job_names.include?(job_name) && job_name =~ job_regex else job_name =~ job_regex end end