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, job_names, job_regex) ⇒ JobRestorer

Returns a new instance of JobRestorer.



5
6
7
8
9
10
11
# 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

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

#job_namesObject (readonly)

Returns the value of attribute job_names.



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

def job_names
  @job_names
end

#job_regexObject (readonly)

Returns the value of attribute job_regex.



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

def job_regex
  @job_regex
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



13
14
15
16
17
18
19
20
# 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!Object



22
23
24
25
26
27
28
29
30
31
32
33
34
# 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