Skip to content

Commit

Permalink
Merge pull request #389 from jhoblitt/bugfix/plugin-extension-handling
Browse files Browse the repository at this point in the history
remove seperate resources for handling plugin extension
  • Loading branch information
R. Tyler Croy committed Oct 10, 2015
2 parents 4b0cd6e + 32c015e commit 24e669d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 33 deletions.
36 changes: 11 additions & 25 deletions manifests/plugin.pp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
) {
include ::jenkins::params

$plugin = "${name}.hpi"
$plugin_parent_dir = inline_template('<%= @plugin_dir.split(\'/\')[0..-2].join(\'/\') %>')
validate_bool($manage_config)
validate_bool($enabled)
Expand All @@ -58,6 +57,15 @@
$search = "${name} "
}

# if $source is specified, it overrides any other URL construction
$download_url = $source ? {
undef => "${base_url}${name}.hpi",
default => $source,
}

$plugin_ext = regsubst($download_url, '^.*\.(hpi|jpi)$', '\1')
$plugin = "${name}.${plugin_ext}"

if (!defined(File[$plugin_dir])) {
if (!defined(File[$plugin_parent_dir])) {
# ensure ownership only when it's home directory for the new user
Expand Down Expand Up @@ -123,31 +131,9 @@
notify => Service['jenkins'],
}

# Create disabled file for jpi extensions too.
file { "${plugin_dir}/${name}.jpi.disabled":
ensure => $enabled_ensure,
file { "${plugin_dir}/${plugin}.pinned":
owner => $username,
mode => '0644',
require => File["${plugin_dir}/${plugin}"],
notify => Service['jenkins'],
}

# create a pinned file if the plugin has a .jpi extension
# to override the builtin module versions
exec { "create-pinnedfile-${name}" :
command => "touch ${plugin_dir}/${name}.jpi.pinned",
cwd => $plugin_dir,
require => File[$plugin_dir],
path => ['/usr/bin', '/usr/sbin', '/bin'],
onlyif => "test -f ${plugin_dir}/${name}.jpi -a ! -f ${plugin_dir}/${name}.jpi.pinned",
before => Archive::Download[$plugin],
user => $username,
}

# if $source is specified, it overrides any other URL construction
$download_url = $source ? {
undef => "${base_url}${plugin}",
default => $source,
require => Archive::Download[$plugin],
}

if $digest_string == '' {
Expand Down
30 changes: 22 additions & 8 deletions spec/defines/jenkins_plugin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,6 @@
:ensure => 'present',
:owner => 'jenkins',
})}
it { should contain_file('/var/lib/jenkins/plugins/myplug.jpi.disabled').with({
:ensure => 'present',
:owner => 'jenkins',
})}
end

describe 'with enabled is true' do
Expand All @@ -85,10 +81,6 @@
:ensure => 'absent',
:owner => 'jenkins',
})}
it { should contain_file('/var/lib/jenkins/plugins/myplug.jpi.disabled').with({
:ensure => 'absent',
:owner => 'jenkins',
})}
end

describe 'with proxy' do
Expand Down Expand Up @@ -216,4 +208,26 @@
end
end # validate_string
end # source

context 'pinned file' do
let(:title) { 'foo' }

context 'default params' do
it do
should contain_file('/var/lib/jenkins/plugins/foo.hpi.pinned').with(
:owner => 'jenkins',
).that_requires('Archive::Download[foo.hpi]')
end
end

context 'with source param' do
let(:params) {{ :source => 'foo.jpi' }}

it do
should contain_file('/var/lib/jenkins/plugins/foo.jpi.pinned').with(
:owner => 'jenkins',
).that_requires('Archive::Download[foo.jpi]')
end
end
end # pinned file extension name
end

0 comments on commit 24e669d

Please sign in to comment.