Skip to content

Commit

Permalink
add executors param to jenkins class
Browse files Browse the repository at this point in the history
Similar semantics as `class { 'jenkins::slave': executors => ... }` but for
the Jenkins master.
  • Loading branch information
Joshua Hoblitt authored and jhoblitt committed May 2, 2015
1 parent c7ed73b commit f693e20
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 1 deletion.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ puppet module install rtyler/jenkins
```
Then the service should be running at [http://hostname.example.com:8080/](http://hostname.example.com:8080/).

### Jenkin's options

#### Master Executor Threads

```puppet
class { 'jenkins':
executors => 0,
}
```

### Managing Jenkins jobs


Expand Down
19 changes: 19 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,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':
Expand Down Expand Up @@ -140,6 +143,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)
Expand All @@ -153,6 +157,10 @@
validate_array($no_proxy_list)
}

if $executors {
validate_integer($executors)
}

anchor {'jenkins::begin':}
anchor {'jenkins::end':}

Expand Down Expand Up @@ -202,6 +210,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] ->
Class['jenkins::config'] ->
Expand Down
31 changes: 30 additions & 1 deletion spec/acceptance/class_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,33 @@ class {'jenkins':
end

end
end

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 ' <numExecutors>42</numExecutors>' }
end
end # executors
end
29 changes: 29 additions & 0 deletions spec/classes/jenkins_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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, /to be an Integer/)
end
end
end # executors =>
end
end

0 comments on commit f693e20

Please sign in to comment.