Sha256: 8c3ee437c16474881bacde12cd55f96c76c8a5940fa15b503fac1dc1f5e50e23

Contents?: true

Size: 974 Bytes

Versions: 1

Compression:

Stored size: 974 Bytes

Contents

require 'jenkins_api_client'
module Jenkinson
  class API
    attr_reader :client

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

    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
  
    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?
        File.open(job, "w") do |xml_file|
          xml_file << job_on_server
        end
      end
    end

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jenkinson-0.0.3 lib/jenkinson/api.rb