Skip to content

Commit

Permalink
Merge pull request voxpupuli#190 from jenkinsci/pr/134
Browse files Browse the repository at this point in the history
Rework of custom update center usage
  • Loading branch information
R. Tyler Croy committed Sep 28, 2014
2 parents 6d21cd8 + 0ce4e28 commit 77b3b9c
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 22 deletions.
6 changes: 0 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ before_install: gem install bundler -v '~> 1.6.0' --no-ri --no-rdoc
bundler_args: "--without development plugins"
script: "bundle exec rake spec SPEC_OPTS='--format documentation'"
rvm:
- 1.8.7
- 1.9.3
- 2.0.0
- 2.1.0
script:
- "bundle exec rake lint"
Expand All @@ -22,10 +20,6 @@ matrix:
exclude:
- rvm: 1.9.3
env: PUPPET_VERSION="~> 2.7.0"
- rvm: 2.0.0
env: PUPPET_VERSION="~> 2.7.0"
- rvm: 2.0.0
env: PUPPET_VERSION="~> 3.1.0"
- rvm: 2.1.0
env: PUPPET_VERSION="~> 2.7.0"
- rvm: 2.1.0
Expand Down
8 changes: 5 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ group :development do
gem 'serverspec'
gem 'vagrant', :github => 'mitchellh/vagrant',
:ref => 'v1.6.5',
:platform => :mri
:platform => [:mri_19, :mri_21]
end

# Vagrant plugins
group :plugins do
gem 'vagrant-aws', :github => 'mitchellh/vagrant-aws'
gem 'vagrant-serverspec', :github => 'jvoorhis/vagrant-serverspec'
gem 'vagrant-aws', :github => 'mitchellh/vagrant-aws',
:platform => [:mri_19, :mri_21]
gem 'vagrant-serverspec', :github => 'jvoorhis/vagrant-serverspec',
:platform => [:mri_19, :mri_21]
end
15 changes: 8 additions & 7 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
#
#
class jenkins::params {
$version = 'installed'
$lts = false
$repo = true
$service_enable = true
$service_ensure = 'running'
$install_java = true
$swarm_version = '1.16'
$version = 'installed'
$lts = false
$repo = true
$service_enable = true
$service_ensure = 'running'
$install_java = true
$swarm_version = '1.16'
$default_plugins_host = 'http://updates.jenkins-ci.org'

case $::osfamily {
'Debian': {
Expand Down
25 changes: 19 additions & 6 deletions manifests/plugin.pp
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,37 @@
# Content of the config file for this plugin. It is up to the caller to
# create this content from a template or any other mean.
#
# update_url = undef
#
define jenkins::plugin(
$version=0,
$version = 0,
$manage_config = false,
$config_filename = undef,
$config_content = undef,
$update_url = undef,
) {
include ::jenkins::params

$plugin = "${name}.hpi"
$plugin_dir = '/var/lib/jenkins/plugins'
$plugin_parent_dir = inline_template('<%= @plugin_dir.split(\'/\')[0..-2].join(\'/\') %>')
validate_bool ($manage_config)
validate_bool($manage_config)
# TODO: validate_str($update_url)

if ($version != 0) {
$base_url = "http://updates.jenkins-ci.org/download/plugins/${name}/${version}/"
$plugins_host = $update_url ? {
undef => $::jenkins::params::default_plugins_host,
default => $update_url,
}
$base_url = "${plugins_host}/download/plugins/${name}/${version}/"
$search = "${name} ${version}(,|$)"
}
else {
$base_url = 'http://updates.jenkins-ci.org/latest/'
$plugins_host = $update_url ? {
undef => $::jenkins::params::default_plugins_host,
default => $update_url,
}
$base_url = "${plugins_host}/latest/"
$search = "${name} "
}

Expand Down Expand Up @@ -70,8 +83,7 @@
}

if (empty(grep([ $::jenkins_plugins ], $search))) {

if ($jenkins::proxy_host){
if ($jenkins::proxy_host) {
Exec {
environment => [
"http_proxy=${jenkins::proxy_host}:${jenkins::proxy_port}",
Expand All @@ -91,6 +103,7 @@
before => Exec["download-${name}"],
}


exec { "download-${name}" :
command => "rm -rf ${name} ${name}.hpi ${name}.jpi && wget --no-check-certificate ${base_url}${plugin}",
cwd => $plugin_dir,
Expand Down
56 changes: 56 additions & 0 deletions spec/defines/jenkins_plugin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,60 @@
it { should contain_exec('download-myplug').with(:environment => ["http_proxy=proxy.company.com:8080", "https_proxy=proxy.company.com:8080"]) }
end


describe 'with a custom update center' do
shared_examples 'execute the right fetch command' do
it 'should wget the plugin' do
expect(subject).to contain_exec('download-git').with({
:command => "rm -rf git git.hpi git.jpi && wget --no-check-certificate #{expected_url}",
})
end
end

let(:title) { 'git' }

context 'by default' do
context 'with a version' do
let(:version) { '1.3.3.7' }
let(:params) { {:version => version} }
let(:expected_url) do
"http://updates.jenkins-ci.org/download/plugins/#{title}/#{version}/#{title}.hpi"
end

include_examples 'execute the right fetch command'
end

context 'without a version' do
let(:expected_url) do
"http://updates.jenkins-ci.org/latest/#{title}.hpi"
end

include_examples 'execute the right fetch command'
end
end

context 'with a custom update_url' do
let(:update_url) { 'http://rspec' }

context 'without a version' do
let(:params) { {:update_url => update_url} }
let(:expected_url) do
"#{update_url}/latest/#{title}.hpi"
end

include_examples 'execute the right fetch command'
end

context 'with a version' do
let(:version) { '1.2.3' }
let(:params) { {:update_url => update_url, :version => version} }
let(:expected_url) do
"#{update_url}/download/plugins/#{title}/#{version}/#{title}.hpi"
end

include_examples 'execute the right fetch command'
end
end
end

end

0 comments on commit 77b3b9c

Please sign in to comment.