From 118dc3406de2d95bab11e5abfbff3f8e3f6fcfdf Mon Sep 17 00:00:00 2001 From: Robert Mestrum Date: Mon, 18 May 2015 14:51:52 +0200 Subject: [PATCH 1/2] add get_slaveagent_port()/set_slaveagent_port() methods to puppet_helper These methods may be used to get/set the portnumber for the slave agent. Eg.: java -jar /usr/lib/jenkins/jenkins-cli.jar -s http://localhost:8080 groovy /usr/lib/jenkins/puppet_helper.groovy get_slaveagent_port java -jar /usr/lib/jenkins/jenkins-cli.jar -s http://localhost:8080 groovy /usr/lib/jenkins/puppet_helper.groovy set_slaveagent_port 42 --- files/puppet_helper.groovy | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/files/puppet_helper.groovy b/files/puppet_helper.groovy index 4a7862fe9..69cbefecf 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 /////////////////////////////////////////////////////////////////////////////// From 6318cfbe325c4429840430c9d7149d10f5304b84 Mon Sep 17 00:00:00 2001 From: Robert Mestrum Date: Tue, 19 May 2015 09:38:17 +0200 Subject: [PATCH 2/2] add slaveagentport param to jenkins class --- manifests/init.pp | 15 +++++++++++++++ spec/acceptance/class_spec.rb | 29 +++++++++++++++++++++++++++++ spec/classes/jenkins_spec.rb | 29 +++++++++++++++++++++++++++++ 3 files changed, 73 insertions(+) diff --git a/manifests/init.pp b/manifests/init.pp index a2903ecce..5bf839890 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': @@ -162,6 +165,7 @@ $port = $jenkins::params::port, $libdir = $jenkins::params::libdir, $executors = undef, + $slaveagentport = undef, ) inherits jenkins::params { validate_bool($lts, $install_java, $repo) @@ -240,6 +244,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