require 'jenkins_api_client' module JenkinsWorkflow # Handles finishing the installation of a new Jenkins server. class Setup attr_accessor :url def initialize(url: nil) @url = url end def list_plugins client.plugin.list_installed end def list_available_plugins client.plugin.list_available end def setup_plugins client.plugin.install('p4') client.plugin.install('workflow-aggregator') puts "Go to the update center at #{url}/updateCenter/ and restart jenkins after everything's installed" end def list_slaves client.node.list end def add_omnibus_build(build_host, os) client.node.create_dumb_slave( name: create_name('omnibus_build', build_host), description: "Omnibus Build Machine at #{build_host}", executors: 1, remote_fs: '/home/vagrant/jenkins', mode: 'exclusive', labels: "build-omnibus-#{os}", slave_user: 'vagrant', slave_host: build_host, private_key_file: '/home/vagrant/.ssh/vagrant_key' ) end def add_test(test_host, os) client.node.create_dumb_slave( name: create_name('package_test', test_host), description: "Package Test Machine at #{test_host}", executors: 1, remote_fs: '/home/vagrant/jenkins', mode: 'exclusive', labels: "test-omnibus-#{os}", slave_user: 'vagrant', slave_host: test_host, private_key_file: '/home/vagrant/.ssh/vagrant_key' ) end def create_name(prefix, host) "#{prefix}_#{host.gsub(/\./, '')}" end private def client JenkinsApi::Client.new(server_url: url, log_level: Logger::WARN) end end end