diff --git a/manifests/init.pp b/manifests/init.pp index 26af37fe8..ae78791e8 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -32,6 +32,9 @@ # config_hash = undef (Default) # Hash with config options to set in sysconfig/jenkins defaults/jenkins # +# executors = undef (Default) +# Integer number of executors on the Jenkin's master. +# # Example use # # class{ 'jenkins': @@ -124,6 +127,7 @@ $cli_try_sleep = $jenkins::params::cli_try_sleep, $port = $jenkins::params::port, $libdir = $jenkins::params::libdir, + $executors = undef, ) inherits jenkins::params { validate_bool($lts, $install_java, $repo) @@ -137,6 +141,8 @@ validate_array($no_proxy_list) } + validate_string($executors) + anchor {'jenkins::begin':} anchor {'jenkins::end':} @@ -177,6 +183,17 @@ include jenkins::cli::reload } + if $executors { + jenkins::cli::exec { 'set_num_executors': + command => ['set_num_executors', $executors], + unless => "[ \$(\$HELPER_CMD get_num_executors) -eq ${executors} ]" + } + + Class['jenkins::cli'] -> + Jenkins::Cli::Exec['set_num_executors'] -> + Class['jenkins::jobs'] + } + Anchor['jenkins::begin'] -> Class['jenkins::package'] -> Class['jenkins::config'] -> diff --git a/spec/acceptance/class_spec.rb b/spec/acceptance/class_spec.rb index 95969d37b..d4af7ed09 100644 --- a/spec/acceptance/class_spec.rb +++ b/spec/acceptance/class_spec.rb @@ -32,4 +32,33 @@ class {'jenkins': end end -end \ No newline at end of file + + context 'executors' do + it 'should work with no errors' do + pp = <<-EOS + class {'jenkins': + executors => 42, + } + EOS + + # Run it twice and test for idempotency + apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, :catch_changes => true) + end + + describe port(8080) do + # jenkins should already have been running so we shouldn't have to + # sleep + it { should be_listening } + end + + describe service('jenkins') do + it { should be_running } + it { should be_enabled } + end + + describe file('/var/lib/jenkins/config.xml') do + it { should contain ' 42' } + end + end # executors +end diff --git a/spec/classes/jenkins_spec.rb b/spec/classes/jenkins_spec.rb index 609c27577..2f86fdd9a 100644 --- a/spec/classes/jenkins_spec.rb +++ b/spec/classes/jenkins_spec.rb @@ -64,5 +64,34 @@ let(:pre_condition) { 'define firewall ($action, $state, $dport, $proto) {}' } it { expect { should raise_error(Puppet::Error) } } end + + describe 'executors =>' do + context 'undef' do + it { should_not contain_class('jenkins::cli_helper') } + it { should_not contain_jenkins__cli__exec('set_num_executors') } + end + + context '42' do + let(:params) {{ :executors => 42 }} + + it { should contain_class('jenkins::cli_helper') } + it do + should contain_jenkins__cli__exec('set_num_executors').with( + :command => ['set_num_executors', 42], + :unless => '[ $($HELPER_CMD get_num_executors) -eq 42 ]', + ) + end + it { should contain_jenkins__cli__exec('set_num_executors').that_requires('Class[jenkins::cli]') } + it { should contain_jenkins__cli__exec('set_num_executors').that_comes_before('Class[jenkins::jobs]') } + end + + context '{}' do + let(:params) {{ :executors => {} }} + + it 'should fail' do + should raise_error(Puppet::Error, /is not a string./) + end + end + end # executors => end end