Skip to content

Commit

Permalink
add source parameter to jenkins::plugin define
Browse files Browse the repository at this point in the history
Direct URL from which to download plugin without modification.  This is
particularly useful for development and testing of plugins which may not be
hosted in the typical Jenkins' plugin directory structure.
  • Loading branch information
Joshua Hoblitt committed May 5, 2015
1 parent 2f72a2d commit c5e8a39
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 1 deletion.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,21 @@ If you need to peg a specific version, simply specify that as a string, i.e.:
}
```

#### Direct URL

Direct URL from which to download plugin without modification. This is
particularly useful for development and testing of plugins which may not be
hosted in the typical Jenkins' plugin directory structure.

```puppet
jenkins::plugin { 'myplugin':
source => 'https://example.org/myplugin.hpi',
}
```

Note that that when `source` is specified, the `version` and `plugin_url`
parameters will have no effect on the plugin retrieval URL.

#### Plugin dependencies
Dependencies are not automatically installed. You need to manually determine the plugin dependencies and include those as well. The Jenkins wiki is a good place to do this. For example: The Git plugin page is at https://wiki.jenkins-ci.org/display/JENKINS/Git+Plugin.

Expand Down
16 changes: 15 additions & 1 deletion manifests/plugin.pp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@
#
# update_url = undef
#
# source = undef
# Direct URL from which to download plugin without modification. This is
# particularly useful for development and testing of plugins which may not be
# hosted in the typical Jenkins' plugin directory structure. E.g.,
#
# https://example.org/myplugin.hpi
#
define jenkins::plugin(
$version = 0,
$manage_config = false,
Expand All @@ -19,6 +26,7 @@
$group = 'jenkins',
$enabled = true,
$create_user = true,
$source = undef,
) {
include ::jenkins::params

Expand All @@ -27,6 +35,7 @@
validate_bool($manage_config)
validate_bool($enabled)
# TODO: validate_str($update_url)
validate_string($source)

if ($version != 0) {
$plugins_host = $update_url ? {
Expand Down Expand Up @@ -132,9 +141,14 @@
before => Exec["download-${name}"],
}

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

exec { "download-${name}" :
command => "rm -rf ${name} ${name}.hpi ${name}.jpi && wget --no-check-certificate ${base_url}${plugin}",
command => "rm -rf ${name} ${name}.hpi ${name}.jpi && wget --no-check-certificate ${download_url}",
cwd => $plugin_dir,
require => [File[$plugin_dir], Package['wget']],
path => ['/usr/bin', '/usr/sbin', '/bin'],
Expand Down
48 changes: 48 additions & 0 deletions spec/defines/jenkins_plugin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,52 @@
end
end

describe 'source' do
shared_examples 'should download from $source url' do
it 'should download from $source url' do
should contain_exec('download-myplug').with(
:command => 'rm -rf myplug myplug.hpi myplug.jpi && wget --no-check-certificate http://e.org/myplug.hpi',
:cwd => '/var/lib/jenkins/plugins',
:environment => nil,
:path => ['/usr/bin', '/usr/sbin', '/bin'],
)
.that_requires('File[/var/lib/jenkins/plugins]')
.that_requires('Package[wget]')
end
end

let(:params) {{ :source => 'http://e.org/myplug.hpi' }}

context 'other params at defaults' do
include_examples 'should download from $source url'
end

context '$update_url is set' do
before { params[:update_url] = 'http://dne.org/' }

include_examples 'should download from $source url'

context 'and $version is set' do
before { params[:version] = 42 }

include_examples 'should download from $source url'
end
end

context 'validate_string' do
context 'string' do
let(:params) {{ :source => 'foo' }}

it { should_not raise_error }
end

context 'array' do
let(:params) {{ :source => [] }}

it 'should fail' do
should raise_error(Puppet::Error, /is not a string/)
end
end
end # validate_string
end # source
end

0 comments on commit c5e8a39

Please sign in to comment.