Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added jenkins_prefix function to retrieve configured prefix #358

Merged
merged 1 commit into from
Aug 15, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions lib/puppet/parser/functions/jenkins_prefix.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

module Puppet::Parser::Functions
newfunction(:jenkins_prefix, :type => :rvalue, :doc => <<-'ENDHEREDOC') do |args|
Return the configured Jenkins prefix value
(corresponds to /etc/defaults/jenkins -> PREFIX)

Example:

$prefix = jenkins_prefix()
ENDHEREDOC

config_hash = lookupvar('::jenkins::config_hash')
if config_hash && \
config_hash['PREFIX'] && \
config_hash['PREFIX']['value']
return config_hash['PREFIX']['value']
else
return lookupvar('::jenkins::params::prefix')
end
end
end
3 changes: 2 additions & 1 deletion manifests/cli.pp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
}

$port = jenkins_port()
$prefix = jenkins_prefix()

# Provide the -i flag if specified by the user.
if $::jenkins::cli_ssh_keyfile {
Expand All @@ -54,7 +55,7 @@
delete_undef_values([
'java',
"-jar ${::jenkins::cli::jar}",
"-s http://localhost:${port}",
"-s http://localhost:${port}${prefix}",
$auth_arg,
]),
' '
Expand Down
3 changes: 2 additions & 1 deletion manifests/cli_helper.pp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
$libdir = $::jenkins::libdir
$cli_jar = $::jenkins::cli::jar
$port = jenkins_port()
$prefix = jenkins_prefix()

$helper_groovy = "${libdir}/puppet_helper.groovy"
file {$helper_groovy:
Expand All @@ -34,7 +35,7 @@
delete_undef_values([
'/usr/bin/java',
"-jar ${::jenkins::cli::jar}",
"-s http://127.0.0.1:${port}",
"-s http://127.0.0.1:${port}${prefix}",
$auth_arg,
"groovy ${helper_groovy}",
]),
Expand Down
1 change: 1 addition & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
$swarm_version = '1.22'
$default_plugins_host = 'https://updates.jenkins-ci.org'
$port = '8080'
$prefix = ''
$cli_tries = 10
$cli_try_sleep = 10
$package_cache_dir = '/var/cache/jenkins_pkgs'
Expand Down
35 changes: 35 additions & 0 deletions spec/functions/jenkins_prefix_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
require 'spec_helper'

# Skip this example block under puppet-4 as it will fail with rspec-puppet
# 2.1.0.
#
# https://github.com/rodjek/rspec-puppet/issues/282
describe 'jenkins_prefix', :if => Puppet.version.to_f < 4.0 do

let(:facts) { { :osfamily => 'RedHat', :operatingsystem => 'RedHat' } }
let(:pre_condition) { 'include ::jenkins' }
# Lazily loaded function call to be used in examples. Not overwriting
# `subject` since rspec-puppet is already defining that to return the
# function
let(:prefix) {
subject.call([])
}

it 'should default to ""' do
expect(prefix).to eql ''
end

context 'with overwritten configuration' do
let(:pre_condition) do
<<-ENDPUPPET
class { 'jenkins':
config_hash => {'PREFIX' => {'value' => '/test'}},
}
ENDPUPPET
end

it 'should be our overwritten prefix' do
expect(prefix).to eql('/test')
end
end
end