Class: Jenkinson::API
- Inherits:
-
Object
- Object
- Jenkinson::API
- Defined in:
- lib/jenkinson/api.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
- #create_or_update_jobs(jobs_folder) ⇒ Object
- #get_jobs_config(target_dir) ⇒ Object
-
#initialize(config) ⇒ API
constructor
A new instance of API.
- #install_plugins(plugins_str) ⇒ Object
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
#client ⇒ Object (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_folder) ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/jenkinson/api.rb', line 10 def create_or_update_jobs(jobs_folder) jobs = Dir["#{jobs_folder}/*/config.xml"] jobs.each do |job| File.open(job, "rb") do |xml_file| jobname = job.split('/')[-2] client.job.create_or_update(jobname, xml_file.read) end end end |
#get_jobs_config(target_dir) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/jenkinson/api.rb', line 20 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}/config.xml" next if job_on_server.nil? dirname = File.dirname(job) Dir.mkdir(dirname) unless Dir.exist?(dirname) File.open(job, "w") do |xml_file| xml_file << job_on_server end end end |
#install_plugins(plugins_str) ⇒ Object
35 36 37 38 39 40 |
# File 'lib/jenkinson/api.rb', line 35 def install_plugins(plugins_str) plugins = plugins_str.split(',') plugins.each do |plugin| client.plugin.install(plugin) end end |