Skip to content

Commit

Permalink
add swarm client args string to support multiple arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
Alvin Huang authored and R. Tyler Croy committed Oct 31, 2016
1 parent 550441e commit 5872d30
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 7 deletions.
15 changes: 14 additions & 1 deletion manifests/slave.pp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@
# parameter so the `::jenkins` class does not need to be the catalog for
# slave only nodes.
#
# [*swarm_client_args*]
# Swarm client arguments to add to slave command line. More info: https://github.com/jenkinsci/swarm-plugin/blob/master/client/src/main/java/hudson/plugins/swarm/Options.java
#

# === Examples
#
Expand Down Expand Up @@ -132,6 +135,7 @@
$source = undef,
$java_args = undef,
$proxy_server = undef,
$swarm_client_args = undef,
) inherits jenkins::params {
validate_string($slave_name)
validate_string($description)
Expand All @@ -147,7 +151,6 @@
if $slave_uid { validate_integer($slave_uid) }
validate_absolute_path($slave_home)
validate_re($slave_mode, '^normal$|^exclusive$')
validate_bool($disable_ssl_verification)
validate_string($tool_locations)
validate_bool($install_java)
validate_bool($manage_client_jar)
Expand Down Expand Up @@ -184,6 +187,16 @@
}
}

if $swarm_client_args {
if is_array($swarm_client_args) {
$_combined_swarm_client_args = hiera_array('jenkins::slave::swarm_client_args', $swarm_client_args)
$_real_swarm_client_args = join($_combined_swarm_client_args, ' ')
}
else {
$_real_swarm_client_args = $swarm_client_args
}
}

if $install_java and ($::osfamily != 'Darwin') {
# Currently the puppetlabs/java module doesn't support installing Java on
# Darwin
Expand Down
32 changes: 27 additions & 5 deletions spec/classes/jenkins_slave_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@
it { should contain_user('jenkins-slave_user').with_uid(nil) }
end

describe 'with ssl verification disabled' do
let(:params) { { :disable_ssl_verification => true } }
it { should contain_file(slave_runtime_file).with_content(/-disableSslVerification/) }
end

describe 'with auto discovery address' do
let(:params) { { :autodiscoveryaddress => '255.255.255.0' } }
it { should contain_file(slave_runtime_file).with_content(/^AUTO_DISCOVERY_ADDRESS="255.255.255.0"$/) }
Expand Down Expand Up @@ -112,6 +107,33 @@
end
end

describe 'with swarm_client_args as a string' do
let(:args) { '-disableSslVerification -disableClientsUniqueId' }
let(:params) do
{
:swarm_client_args => args
}
end

it 'should set swarm_client_args' do
should contain_file(slave_runtime_file).with_content(/^OTHER_ARGS=" #{args}"$/)
end
end

describe 'with swarm_client_args as an array' do
let(:args) { ['-disableSslVerification', '-disableClientsUniqueId' ] }
let(:params) do
{
:swarm_client_args => args
}
end

it 'should convert swarm_client_args to a string' do
args_as_string = args.join ' '
should contain_file(slave_runtime_file).with_content(/^OTHER_ARGS=" #{args_as_string}"$/)
end
end

describe 'with LABELS as an array' do
let(:params) do
{
Expand Down
2 changes: 1 addition & 1 deletion templates/jenkins-slave-defaults.erb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ DESCRIPTION="<%= @description -%>"
JENKINS_USERNAME=<%= @quoted_ui_user %>
JENKINS_PASSWORD=<%= @quoted_ui_pass %>

OTHER_ARGS="<%= '-disableSslVerification' if @disable_ssl_verification -%>"
OTHER_ARGS="<%= '-disableSslVerification' if @disable_ssl_verification -%> <%= @_real_swarm_client_args %>"
DISABLE_UNIQUE="<%= '-disableClientsUniqueId' if @disable_clients_unique_id -%>"

if [ -n "$JENKINS_USERNAME" ]; then
Expand Down

0 comments on commit 5872d30

Please sign in to comment.