Class: Jenkinson::API

Inherits:
Object
  • Object
show all
Defined in:
lib/jenkinson/api.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ API

Returns a new instance of API.



6
7
8
# File 'lib/jenkinson/api.rb', line 6

def initialize(config)
  @client = JenkinsApi::Client.new(config)
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



4
5
6
# File 'lib/jenkinson/api.rb', line 4

def client
  @client
end

Instance Method Details

#create_or_update_jobs(jobs) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/jenkinson/api.rb', line 10

def create_or_update_jobs(jobs)
  jobs.each do |job|
    File.open(job, "rb") do |xml_file|
      jobname = File.basename( job, ".*")
      client.job.create_or_update(jobname, xml_file.read)
    end
  end
end

#get_jobs_config(target_dir) ⇒ Object



19
20
21
22
23
24
25
26
27
28
# File 'lib/jenkinson/api.rb', line 19

def get_jobs_config(target_dir)
  client.job.list_all.each do |jobname|
    job_on_server = client.job.get_config(jobname) rescue nil
    job = "#{target_dir}/#{jobname}.xml"
    next if job_on_server.nil?
    File.open(job, "w") do |xml_file|
      xml_file << job_on_server
    end
  end
end

#install_plugins(plugins_str) ⇒ Object



30
31
32
33
34
35
# File 'lib/jenkinson/api.rb', line 30

def install_plugins(plugins_str)
  plugins = plugins_str.split(',')
  plugins.each do |plugin|
    client.plugin.install(plugin)
  end
end