diff --git a/manifests/plugin.pp b/manifests/plugin.pp index 8682b3fbc..6872c51c3 100644 --- a/manifests/plugin.pp +++ b/manifests/plugin.pp @@ -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) @@ -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 @@ -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 == '' { diff --git a/spec/defines/jenkins_plugin_spec.rb b/spec/defines/jenkins_plugin_spec.rb index e8ec64c20..48ba08898 100644 --- a/spec/defines/jenkins_plugin_spec.rb +++ b/spec/defines/jenkins_plugin_spec.rb @@ -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 @@ -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 @@ -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