Class: LeeroyJenkins::JobRestorer

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(jenkins_client, backup_dir, threads) ⇒ JobRestorer

Returns a new instance of JobRestorer.



5
6
7
8
9
# File 'lib/leeroy_jenkins/job_restorer.rb', line 5

def initialize(jenkins_client, backup_dir, threads)
  @jenkins_client = jenkins_client
  @backup_dir = backup_dir
  @threads = threads
end

Instance Attribute Details

#backup_dirObject (readonly)

Returns the value of attribute backup_dir.



3
4
5
# File 'lib/leeroy_jenkins/job_restorer.rb', line 3

def backup_dir
  @backup_dir
end

#jenkins_clientObject (readonly)

Returns the value of attribute jenkins_client.



3
4
5
# File 'lib/leeroy_jenkins/job_restorer.rb', line 3

def jenkins_client
  @jenkins_client
end

#threadsObject (readonly)

Returns the value of attribute threads.



3
4
5
# File 'lib/leeroy_jenkins/job_restorer.rb', line 3

def threads
  @threads
end

Instance Method Details

#dry_runObject



11
12
13
14
15
16
17
18
# File 'lib/leeroy_jenkins/job_restorer.rb', line 11

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

  Hash[pairs]
end

#restore!Object



20
21
22
23
24
25
26
27
28
# File 'lib/leeroy_jenkins/job_restorer.rb', line 20

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

  Hash[pairs]
end