Skip to content

Commit

Permalink
Use new facter-based method of detecting installed plugin versions ba…
Browse files Browse the repository at this point in the history
…sed on approach suggested by jlambert121
  • Loading branch information
jchristi committed Nov 28, 2013
1 parent 75f8cc6 commit 5b7b9ef
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 14 deletions.
32 changes: 32 additions & 0 deletions lib/facter/jenkins.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# jenkins.rb
#
# Creates a fact 'jenkins_plugins' containing a comma-delimited string of all
# jenkins plugins + versions.
#
jenkins_home = Facter::Util::Resolution.exec("echo ~jenkins")
plugins = "#{jenkins_home}/plugins"
jenkins_plugins = ''

if File.directory?(jenkins_home)
# Get a list of all plugins + versions
Dir.entries(plugins).select do |plugin|
if (File.directory?("#{plugins}/#{plugin}") == true) && !(plugin == '..' || plugin == '.')
begin
contents = File.read("#{plugins}/#{plugin}/META-INF/MANIFEST.MF")
contents =~ (/Plugin\-Version:\s+([\d\.]+)/)
version = $1
jenkins_plugins = "#{plugin} #{version}, " + jenkins_plugins
rescue
# Nothing really to do about it, failing means no version which will
# result in a new plugin if needed
end
end
end
Facter.add('jenkins_plugins') do
setcode do
jenkins_plugins
end
end
else
# Does not have jenkins installed
end
24 changes: 10 additions & 14 deletions manifests/plugin.pp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@

if ($version != 0) {
$base_url = "http://updates.jenkins-ci.org/download/plugins/${name}/${version}/"
$search = "${name} ${version},"
}
else {
$base_url = 'http://updates.jenkins-ci.org/latest/'
$search = "${name} "
}

if (!defined(File[$plugin_dir])) {
Expand Down Expand Up @@ -47,28 +49,22 @@
}
}

if (!defined(File[$plugin_installed])) {
file {
$plugin_installed :
mode => '0777',
content => template("jenkins/plugin-is-installed.erb");
if (empty(grep([ $::jenkins_plugins ], $search))) {
exec {
"download-${name}" :
command => "rm -rf ${name} ${name}.* && wget --no-check-certificate ${base_url}${plugin}",
cwd => $plugin_dir,
require => [File[$plugin_dir], Package['wget']],
path => ['/usr/bin', '/usr/sbin',],
}
}

exec {
"download-${name}" :
command => "rm -rf ${name} ${name}.* && wget --no-check-certificate ${base_url}${plugin}",
cwd => $plugin_dir,
require => [File[$plugin_dir], Package['wget'], File[$plugin_installed]],
path => ['/usr/bin', '/usr/sbin',],
unless => "bash ${plugin_installed} ${name} ${version}";
}

file {
"${plugin_dir}/${plugin}" :
require => Exec["download-${name}"],
owner => 'jenkins',
mode => '0644',
notify => Service['jenkins'];
}

}

0 comments on commit 5b7b9ef

Please sign in to comment.