diff --git a/files/puppet_helper.groovy b/files/puppet_helper.groovy index 3652da8bd..b77e783ad 100644 --- a/files/puppet_helper.groovy +++ b/files/puppet_helper.groovy @@ -312,6 +312,30 @@ class Actions { j.setNumExecutors(n.toInteger()) j.save() } + + //////////////////////// + // get_slaveagent_port + //////////////////////// + /* + * Print the portnumber of the slave agent + */ + void get_slaveagent_port() { + def j = Jenkins.getInstance() + def n = j.getSlaveAgentPort() + out.println(n) + } + + //////////////////////// + // set_slaveagent_port + //////////////////////// + /* + * Set the portnumber of the slave agent + */ + void set_slaveagent_port(String n) { + def j = Jenkins.getInstance() + j.setSlaveAgentPort(n.toInteger()) + j.save() + } } // class Actions /////////////////////////////////////////////////////////////////////////////// diff --git a/manifests/init.pp b/manifests/init.pp index 42c8cb813..8542b7582 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -47,6 +47,9 @@ # executors = undef (Default) # Integer number of executors on the Jenkin's master. # +# slaveagentport = undef (Default) +# Integer number of portnumber for the slave agent. +# # Example use # # class{ 'jenkins': @@ -171,6 +174,7 @@ $port = $jenkins::params::port, $libdir = $jenkins::params::libdir, $executors = undef, + $slaveagentport = undef, ) inherits jenkins::params { validate_bool($lts, $install_java, $repo) @@ -249,6 +253,17 @@ Class['jenkins::jobs'] } + if $slaveagentport { + jenkins::cli::exec { 'set_slaveagent_port': + command => ['set_slaveagent_port', $slaveagentport], + unless => "[ \$(\$HELPER_CMD get_slaveagent_port) -eq ${slaveagentport} ]" + } + + Class['jenkins::cli'] -> + Jenkins::Cli::Exec['set_slaveagent_port'] -> + Class['jenkins::jobs'] + } + Anchor['jenkins::begin'] -> Class[$jenkins_package_class] -> Class['jenkins::config'] -> diff --git a/spec/acceptance/class_spec.rb b/spec/acceptance/class_spec.rb index d4af7ed09..fa071a636 100644 --- a/spec/acceptance/class_spec.rb +++ b/spec/acceptance/class_spec.rb @@ -61,4 +61,33 @@ class {'jenkins': it { should contain ' 42' } end end # executors + + context 'slaveagentport' do + it 'should work with no errors' do + pp = <<-EOS + class {'jenkins': + slaveagentport => 7777, + } + 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 ' 7777' } + end + end # slaveagentport end diff --git a/spec/classes/jenkins_spec.rb b/spec/classes/jenkins_spec.rb index 618ce9ab3..d9ac4836e 100755 --- a/spec/classes/jenkins_spec.rb +++ b/spec/classes/jenkins_spec.rb @@ -93,5 +93,34 @@ end end end # executors => + + describe 'slaveagentport =>' do + context 'undef' do + it { should_not contain_class('jenkins::cli_helper') } + it { should_not contain_jenkins__cli__exec('set_slaveagent_port') } + end + + context '7777' do + let(:params) {{ :slaveagentport => 7777 }} + + it { should contain_class('jenkins::cli_helper') } + it do + should contain_jenkins__cli__exec('set_slaveagent_port').with( + :command => ['set_slaveagent_port', 42], + :unless => '[ $($HELPER_CMD get_slaveagent_port) -eq 7777 ]', + ) + end + it { should contain_jenkins__cli__exec('set_slaveagent_port').that_requires('Class[jenkins::cli]') } + it { should contain_jenkins__cli__exec('set_slaveagent_port').that_comes_before('Class[jenkins::jobs]') } + end + + context '{}' do + let(:params) {{ :slaveagentport => {} }} + + it 'should fail' do + should raise_error(Puppet::Error, /to be an Integer/) + end + end + end # slaveagentport => end end