summaryrefslogtreecommitdiffstats
path: root/puppet/modules/jenkins_server/manifests/plugin.pp
blob: 3cc4c25df42ad13ce371a71ad23818bfff89993f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# installs (or removes) a Jenkins plugin.
# Doesn't automatically restart Jenkins to load the plugin, so the plugin won't appear
# until the next restart.
#
# $name is the short name of the Jenkins plugin (as observed under
# http://updates.jenkins-ci.org/download/plugins/ ).
#
# $ensure may be one of 'present', 'absent', or a version string.
# 'present' implies the latest available version.
#
# Note that it is currently not possible to change the version of a plugin which is
# already installed (e.g. changing 'ensure => present' to 'ensure => "0.0.1"' will not
# downgrade an already-installed plugin).
#
define jenkins_server::plugin(
    $ensure = 'present'
) {

    $url = $ensure ? {
        'present' => "http://updates.jenkins-ci.org/latest/$name.hpi",
        default => "http://updates.jenkins-ci.org/download/plugins/$name/$ensure/$name.hpi",
    }

    $plugins_dir = "/var/lib/jenkins/plugins"

    # note: although the URL above uses .hpi (hudson plug-in) as the file extension,
    # the Jenkins plugin center renames .hpi to .jpi when installing, so we will do the same
    # for compatibility.
    $filename = "$plugins_dir/$name.jpi"

    case $ensure {

        'absent': {
            file { $filename:
                ensure => absent,
            }
        }

        default: {
            # note: --no-check-certificate because updates.jenkins-ci.org SSL setup is broken. Bad!
            exec { "install jenkins plugin $url -> $filename":
                command =>
                    "/bin/su -c '\
                        \
                        wget --no-check-certificate -O $name.jpi.downloading $url && \
                        mv $name.jpi.downloading $filename \
                        \
                    ' - jenkins"
                ,
                require => [
                    File[$plugins_dir],
                    Package["jenkins"],
                ],
                creates => $filename,
                logoutput => true,
            }
        }
    }

}