diff --git a/.fixtures.yml b/.fixtures.yml index 2f6d0b3db..087ac25d1 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -6,7 +6,6 @@ fixtures: zypprepo: "https://github.com/voxpupuli/puppet-zypprepo.git" archive: "https://github.com/voxpupuli/puppet-archive.git" systemd: "https://github.com/voxpupuli/puppet-systemd" - transition: "https://github.com/puppetlabs/puppetlabs-transition" yumrepo_core: repo: https://github.com/puppetlabs/puppetlabs-yumrepo_core.git puppet_version: ">= 6.0.0" diff --git a/README.md b/README.md index 770c24890..a3e98cb80 100644 --- a/README.md +++ b/README.md @@ -207,7 +207,7 @@ configuration are all driven through this script. When an API-based resource is defined, the Jenkins' CLI is installed and run against the local system (127.0.0.1). Jenkins is assumed to be listening on port 8080, but the module is smart enough to notice if you've configured an -alternate port using jenkins::config_hash['HTTP_PORT']. +alternate port using jenkins::config_hash['JENKINS_PORT']. Users and credentials are Puppet-managed, meaning that changes made to them from outside Puppet will be reset at the next puppet run. In this way, you can diff --git a/lib/facter/jenkins.rb b/lib/facter/jenkins.rb index b1b0f0bff..f3271f21c 100644 --- a/lib/facter/jenkins.rb +++ b/lib/facter/jenkins.rb @@ -12,25 +12,3 @@ plugins.keys.sort.map { |plugin| "#{plugin} #{plugins[plugin][:plugin_version]}" }.join(', ') end end - -Facter.add(:jenkins_version) do - confine kernel: 'Linux' - - setcode do - libdir = case Facter.value('os.family') - when 'Debian' - '/usr/share/jenkins' - when 'Archlinux' - '/usr/share/java/jenkins' - else - '/usr/lib/jenkins' - end - war = libdir + '/jenkins.war' - - if Facter::Util::Resolution.which('java') and File.exist?(war) - Facter::Util::Resolution.exec( - 'java -jar %s --version' % [war] - ) - end - end -end diff --git a/lib/puppet/parser/functions/jenkins_port.rb b/lib/puppet/parser/functions/jenkins_port.rb index dcde7afc8..9405c2d3e 100644 --- a/lib/puppet/parser/functions/jenkins_port.rb +++ b/lib/puppet/parser/functions/jenkins_port.rb @@ -10,12 +10,6 @@ module Puppet::Parser::Functions ENDHEREDOC config_hash = lookupvar('::jenkins::config_hash') - if config_hash && \ - config_hash['HTTP_PORT'] && \ - config_hash['HTTP_PORT']['value'] - return config_hash['HTTP_PORT']['value'] - else - return 8080 - end + config_hash&.dig('JENKINS_PORT', 'value') || 8080 end end diff --git a/lib/puppet/parser/functions/jenkins_prefix.rb b/lib/puppet/parser/functions/jenkins_prefix.rb index 648486fc8..f88755edb 100644 --- a/lib/puppet/parser/functions/jenkins_prefix.rb +++ b/lib/puppet/parser/functions/jenkins_prefix.rb @@ -10,12 +10,6 @@ module Puppet::Parser::Functions ENDHEREDOC config_hash = lookupvar('::jenkins::config_hash') - if config_hash && \ - config_hash['PREFIX'] && \ - config_hash['PREFIX']['value'] - return config_hash['PREFIX']['value'] - else - return '' - end + config_hash&.dig('PREFIX', 'value') || '' end end diff --git a/lib/puppet/x/jenkins/config.rb b/lib/puppet/x/jenkins/config.rb index 7e5fba991..899e879f1 100644 --- a/lib/puppet/x/jenkins/config.rb +++ b/lib/puppet/x/jenkins/config.rb @@ -11,10 +11,10 @@ class Puppet::X::Jenkins::Config class UnknownConfig < ArgumentError; end DEFAULTS = { - cli_jar: '/usr/lib/jenkins/jenkins-cli.jar', + cli_jar: '/usr/share/java/jenkins-cli.jar', url: 'http://localhost:8080', ssh_private_key: nil, - puppet_helper: '/usr/lib/jenkins/puppet_helper.groovy', + puppet_helper: '/usr/share/java/puppet_helper.groovy', cli_tries: 30, cli_try_sleep: 2, cli_username: nil, diff --git a/manifests/config.pp b/manifests/config.pp index d0699cccd..597d2ffc9 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -13,5 +13,9 @@ $jenkins::params::config_hash_defaults, $jenkins::config_hash ) - create_resources('jenkins::sysconfig', $config_hash) + + systemd::dropin_file { 'puppet-overrides.conf': + unit => 'jenkins.service', + content => epp("${module_name}/jenkins-override.epp", { 'environment' => $config_hash }), + } } diff --git a/manifests/init.pp b/manifests/init.pp index d89121c8f..955a72899 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -2,10 +2,9 @@ # This class manages the [Jenkins CI/CD service](https://jenkins.io/index.html). # # Note that if different jenkins listening port(s) are configured via -# ``jenkins::port``, ``jenkins::config_hash`` and/or a ``jenkins::sysconf`` -# resource, "bad things" are likely to happen. This is a known implementation -# problem with this module that can not be fixed without breaking backwards -# compatibility. +# ``jenkins::port`` and ``jenkins::config_hash`` resource, "bad things" are +# likely to happen. This is a known implementation problem with this module +# that can not be fixed without breaking backwards compatibility. # # @param version # package to install @@ -79,8 +78,7 @@ # @example Bulk sysconf # class{ 'jenkins': # config_hash => { -# 'HTTP_PORT' => { 'value' => '9090' }, -# 'AJP_PORT' => { 'value' => '9009' }, +# 'JENKINS_PORT' => { 'value' => '9090' }, # } # } # @@ -205,16 +203,6 @@ # @param libdir # Path to jenkins core files # -# * Redhat: ``/usr/lib/jenkins`` -# * Debian: ``/usr/share/jenkins`` -# -# @param sysconfdir -# Controls the path to the "sysconfig" file that stores jenkins service -# start-up variables -# -# * RedHat: ``/etc/sysconfig/jenkins`` -# * Debian: ``/etc/default/jenkins`` -# # @param manage_datadirs # manage the local state dir, plugins dir and jobs dir # @@ -282,9 +270,6 @@ # version: '2.16.0' # # /support-core deps # -# @param systemd_type -# Define a systemd unit type -# class jenkins ( String $version = 'installed', Boolean $lts = true, @@ -296,7 +281,7 @@ Boolean $manage_service = true, Boolean $service_enable = true, Enum['running', 'stopped'] $service_ensure = 'running', - Optional[String] $service_provider = $jenkins::params::service_provider, + Optional[String] $service_provider = undef, Hash $config_hash = {}, Hash $plugin_hash = {}, Hash $job_hash = {}, @@ -315,8 +300,7 @@ Integer $cli_tries = 10, Integer $cli_try_sleep = 10, Integer $port = 8080, - Stdlib::Absolutepath $libdir = $jenkins::params::libdir, - Stdlib::Absolutepath $sysconfdir = $jenkins::params::sysconfdir, + Stdlib::Absolutepath $libdir = '/usr/share/java', Boolean $manage_datadirs = true, Stdlib::Absolutepath $localstatedir = '/var/lib/jenkins', Optional[Integer] $executors = undef, @@ -328,7 +312,6 @@ Variant[Array[String], Hash[String, Hash]] $default_plugins = $jenkins::params::default_plugins, String $default_plugins_host = 'https://updates.jenkins.io', Boolean $purge_plugins = false, - Enum['simple', 'forking'] $systemd_type = $jenkins::params::systemd_type, ) inherits jenkins::params { if $purge_plugins and ! $manage_datadirs { warning('jenkins::purge_plugins has no effect unless jenkins::manage_datadirs is true') @@ -394,17 +377,20 @@ notice(sprintf('INFO: make sure you install the following plugins with your code using this module: %s',join($jenkins::params::default_plugins,','))) # lint:ignore:140chars } - if $service_provider == 'systemd' { - jenkins::systemd { 'jenkins': - user => $user, - libdir => $libdir, - } + # puppet/jenkins used to implement systemd but Jenkins 2.332 moved to + # systemd and implements this natively. Clean up the old implementation. + $old_libdir = $facts['os']['family'] ? { + 'Archlinux' => '/usr/share/java/jenkins/', + 'Debian' => '/usr/share/jenkins', + default => '/usr/lib/jenkins', + } + file { "${old_libdir}/jenkins-run": + ensure => absent, + } - # jenkins::config manages the jenkins user resource, which is autorequired - # by the file resource for the run wrapper. - Class['jenkins::config'] - -> Jenkins::Systemd['jenkins'] - -> Anchor['jenkins::end'] + file { '/etc/systemd/system/jenkins.service': + ensure => absent, + notify => Service['jenkins'], } } diff --git a/manifests/params.pp b/manifests/params.pp index 395f0c32b..3ffb716ee 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -2,7 +2,9 @@ # @api private class jenkins::params { $swarm_version = '2.2' - $_java_args = '-Djava.awt.headless=true -Djenkins.install.runSetupWizard=false' + $config_hash_defaults = { + 'JAVA_OPTS' => { value => '-Djava.awt.headless=true -Djenkins.install.runSetupWizard=false' }, + } $default_plugins = { # Pin to 1074 now - not pretty, but latest is incompatible with LTS now 'credentials' => { 'version' => '1074.v60e6c29b_b_44b_' }, # required by puppet_helper.groovy @@ -12,71 +14,22 @@ 'structs' => {}, # required by credentials plugin } - if versioncmp(pick($facts['jenkins_version'], '2.313'), '2.313') >= 0 { - $systemd_type = 'simple' - } else { - $systemd_type = 'forking' - } - case $facts['os']['family'] { 'Debian': { $repo = true - $libdir = '/usr/share/jenkins' $package_provider = 'dpkg' - $service_provider = undef - $sysconfdir = '/etc/default' - $config_hash_defaults = { - 'JAVA_ARGS' => { value => $_java_args }, - 'AJP_PORT' => { value => '-1' }, - } } 'RedHat': { $repo = true - $libdir = '/usr/lib/jenkins' $package_provider = 'rpm' - $sysconfdir = '/etc/sysconfig' - $config_hash_defaults = { - 'JENKINS_JAVA_OPTIONS' => { value => $_java_args }, - 'JENKINS_AJP_PORT' => { value => '-1' }, - } - - # explicitly use systemd if it is available - # XXX only enable explicit systemd support on RedHat at this time due to - # the Debian packaging using variable interpolation in - # /etc/default/jenkins. - # XXX this param exists because of a historical work around to PUP-5353 - # it is part of the public interface to ::jenkins; it needs to be - # maintained until at least a major version bump. It has been somewhat - # repurposed as a flag for specific systemd support. - if $facts['systemd'] { - $service_provider = 'systemd' - } else { - $service_provider = undef - } } 'Archlinux': { $repo = false - $libdir = '/usr/share/java/jenkins/' $package_provider = 'pacman' - $service_provider = undef - $sysconfdir = '/etc/conf.d' - $config_hash_defaults = { - # Archlinux's jenkins package uses it's own variables - # which are not compatible with these. - #'JENKINS_JAVA_OPTIONS' => { value => $_java_args }, - #'JENKINS_AJP_PORT' => { value => '-1' }, - } } default: { $repo = true - $libdir = '/usr/lib/jenkins' $package_provider = undef - $service_provider = undef - $sysconfdir = '/etc/sysconfig' - $config_hash_defaults = { - 'JENKINS_JAVA_OPTIONS' => { value => $_java_args }, - 'JENKINS_AJP_PORT' => { value => '-1' }, - } } } } diff --git a/manifests/slave.pp b/manifests/slave.pp index 6700a7b49..e80d87fae 100644 --- a/manifests/slave.pp +++ b/manifests/slave.pp @@ -204,17 +204,17 @@ # customizations based on the OS family case $facts['os']['family'] { - 'Debian': { - $defaults_location = $jenkins::params::sysconfdir - - ensure_packages(['daemon']) - Package['daemon'] -> Service['jenkins-slave'] + 'Archlinux': { + $defaults_location = '/etc/conf.d' } 'Darwin': { $defaults_location = $slave_home } + 'Debian': { + $defaults_location = '/etc/default' + } default: { - $defaults_location = $jenkins::params::sysconfdir + $defaults_location = '/etc/sysconfig' } } diff --git a/manifests/sysconfig.pp b/manifests/sysconfig.pp deleted file mode 100644 index 83da2befe..000000000 --- a/manifests/sysconfig.pp +++ /dev/null @@ -1,21 +0,0 @@ -# @summary Configure sysconfig settings -# @api private -define jenkins::sysconfig ( - String $value, -) { - if ($value =~ /\$/) { - warning("Jenkins::Sysconfig[${name}]: detected \'\$\' in value -- be advised the variable interpolation will not work under systemd") - } - - if $jenkins::manage_service { - $notify = Class['jenkins::service'] - } else { - $notify = undef - } - file_line { "Jenkins sysconfig setting ${name}": - path => "${jenkins::sysconfdir}/jenkins", - line => "${name}=\"${value}\"", - match => "^${name}=", - notify => $notify, - } -} diff --git a/manifests/systemd.pp b/manifests/systemd.pp deleted file mode 100644 index 602c72cf1..000000000 --- a/manifests/systemd.pp +++ /dev/null @@ -1,54 +0,0 @@ -# @summary Set up a systemd service and migrate from sysv if applicable -# -# This type handles setting up a systemd service and, if applicable, managing -# the transition from a sysv -> systemd service without leaving zombie services -# running. -# -# @api private -define jenkins::systemd ( - Any $user, - Any $libdir, -) { - assert_private() - $service = $name - - include systemd - - $sysv_init = "/etc/init.d/${service}" - - file { "${libdir}/${service}-run": - content => template("${module_name}/${service}-run.erb"), - owner => $user, - mode => '0700', - notify => Service[$service], - } - - transition { "stop ${service} service": - resource => Service[$service], - attributes => { - # lint:ignore:ensure_first_param - ensure => stopped, - # lint:endignore - }, - prior_to => [ - File[$sysv_init], - ], - } - - # transition can not set a prior_to on - # Systemd::Unit_file['jenkins-slave.service'] as it is not a native type so - # we must us the sysv init script as a proxy - file { $sysv_init: - ensure => 'absent', - # XXX if this is not set, the seluser property will claim is it out - # of sync and the transition resource will always fire. It isn't - # clear if this is a bug or a feature of the file resource. - selinux_ignore_defaults => true, - } - - systemd::unit_file { "${service}.service": - content => template("${module_name}/${service}.service.erb"), - notify => Service[$service], - require => File[$sysv_init], - } -} diff --git a/metadata.json b/metadata.json index 1b7a743e1..4e2e86c5c 100644 --- a/metadata.json +++ b/metadata.json @@ -74,10 +74,6 @@ { "name": "puppet/systemd", "version_requirement": ">= 3.1.0 < 4.0.0" - }, - { - "name": "puppetlabs/transition", - "version_requirement": ">= 0.1.0 < 1.0.0" } ], "requirements": [ diff --git a/spec/acceptance/class_spec.rb b/spec/acceptance/class_spec.rb index bedf4ae05..414522010 100644 --- a/spec/acceptance/class_spec.rb +++ b/spec/acceptance/class_spec.rb @@ -19,7 +19,7 @@ class {'jenkins': } end - describe file("#{LIBDIR}/jenkins-cli.jar") do + describe file('/usr/share/java/jenkins-cli.jar') do it { is_expected.to be_file } it { is_expected.to be_readable.by('owner') } it { is_expected.to be_writable.by('owner') } @@ -27,39 +27,15 @@ class {'jenkins': it { is_expected.to be_readable.by('others') } end - describe file("#{SYSCONFDIR}/jenkins") do + describe file('/etc/systemd/system/jenkins.service.d/puppet-overrides.conf') do it { is_expected.to be_file } - if fact('osfamily') == 'Debian' - it { is_expected.to contain 'AJP_PORT="-1"' } - else - it { is_expected.to contain 'JENKINS_AJP_PORT="-1"' } - end + it { is_expected.to contain 'Environment=' } end describe service('jenkins') do it { is_expected.to be_running } it { is_expected.to be_enabled } end - - if fact('osfamily') == 'RedHat' && SYSTEMD - describe file('/etc/systemd/system/jenkins.service') do - it { is_expected.to be_file } - it { is_expected.to contain "ExecStart=#{libdir}/jenkins-run" } - end - describe file('/etc/init.d/jenkins') do - it { is_expected.not_to exist } - end - describe service('jenkins') do - it { is_expected.to be_running.under('systemd') } - end - else - describe file('/etc/systemd/system/jenkins.service') do - it { is_expected.not_to exist } - end - describe file('/etc/init.d/jenkins') do - it { is_expected.to be_file } - end - end end # default parameters context 'executors' do diff --git a/spec/acceptance/xtypes/jenkins_credentials_spec.rb b/spec/acceptance/xtypes/jenkins_credentials_spec.rb index 0a59d3f60..8f9507325 100644 --- a/spec/acceptance/xtypes/jenkins_credentials_spec.rb +++ b/spec/acceptance/xtypes/jenkins_credentials_spec.rb @@ -7,7 +7,8 @@ context 'present' do context 'UsernamePasswordCredentialsImpl' do it 'works with no errors and idempotently' do - pp = base_manifest + <<-EOS + pp = <<-EOS + include jenkins jenkins_credentials { '9b07d668-a87e-4877-9407-ae05056e32ac': ensure => 'present', description => 'foo', @@ -33,7 +34,8 @@ context 'ConduitCredentialsImpl' do it 'works with no errors and idempotently' do - pp = base_manifest + <<-EOS + pp = <<-EOS + include jenkins jenkins::plugin { 'phabricator-plugin': } @@ -61,7 +63,8 @@ context 'BasicSSHUserPrivateKey' do it 'works with no errors and idempotently' do - pp = base_manifest + <<-EOS + pp = <<-EOS + include jenkins # At least on EL7 version 1.0.4 is shipped and ssh-credentials # needs >= 1.0.5. 1.0.8 is the latests at the time of writing. jenkins::plugin { 'trilead-api': @@ -96,7 +99,8 @@ context 'StringCredentialsImpl' do it 'works with no errors and idempotently' do - pp = base_manifest + <<-EOS + pp = <<-EOS + include jenkins jenkins::plugin { 'plain-credentials': pin => true, } @@ -125,7 +129,8 @@ context 'FileCredentialsImpl' do it 'works with no errors and idempotently' do - pp = base_manifest + <<-EOS + pp = <<-EOS + include jenkins jenkins::plugin { 'plain-credentials': pin => true, } @@ -156,7 +161,8 @@ context 'AWSCredentialsImpl' do it 'works with no errors and idempotently' do pending('jenkins plugin tests are not consistently failing or succeeding: https://github.com/voxpupuli/puppet-jenkins/issues/839') - pp = base_manifest + <<-EOS + pp = <<-EOS + include jenkins jenkins::plugin { [ 'jackson2-api', 'aws-java-sdk', @@ -194,7 +200,8 @@ context 'GitLabApiTokenImpl' do it 'works with no errors and idempotently' do pending('jenkins plugin tests are not consistently failing or succeeding: https://github.com/voxpupuli/puppet-jenkins/issues/839') - pp = base_manifest + <<-EOS + pp = <<-EOS + include jenkins package { 'git': } jenkins::plugin { [ 'matrix-project', @@ -240,7 +247,8 @@ context 'BrowserStackCredentials' do it 'works with no errors and idempotently' do pending('jenkins plugin tests are not consistently failing or succeeding: https://github.com/voxpupuli/puppet-jenkins/issues/839') - pp = base_manifest + <<-EOS + pp = <<-EOS + include jenkins jenkins::plugin { [ 'jackson2-api', 'credentials-binding', @@ -278,7 +286,8 @@ context 'absent' do context 'StringCredentialsImpl' do it 'works with no errors and idempotently' do - pp = base_manifest + <<-EOS + pp = <<-EOS + include jenkins jenkins::plugin { 'plain-credentials': } jenkins_credentials { '150b2895-b0eb-4813-b8a5-3779690c063c': @@ -305,7 +314,8 @@ context 'FileCredentialsImpl' do it 'works with no errors and idempotently' do - pp = base_manifest + <<-EOS + pp = <<-EOS + include jenkins jenkins::plugin { 'plain-credentials': pin => true, } diff --git a/spec/acceptance/xtypes/jenkins_job_spec.rb b/spec/acceptance/xtypes/jenkins_job_spec.rb index 52df6f751..488c086b9 100644 --- a/spec/acceptance/xtypes/jenkins_job_spec.rb +++ b/spec/acceptance/xtypes/jenkins_job_spec.rb @@ -60,7 +60,8 @@ context 'ensure =>' do context 'present' do it 'works with no errors' do - pp = base_manifest + <<-EOS + pp = <<-EOS + include jenkins jenkins_job { 'foo': ensure => present, config => \'#{test_build_job}\', @@ -82,7 +83,8 @@ context 'absent' do it 'works with no errors and idempotently' do - pp = base_manifest + <<-EOS + pp = <<-EOS + include jenkins jenkins_job { 'foo': ensure => absent, } @@ -100,7 +102,8 @@ context 'cloudbees-folder plugin' do let(:manifest) do - base_manifest + <<-EOS + <<-EOS + include jenkins jenkins::plugin { 'cloudbees-folder': } EOS end diff --git a/spec/classes/jenkins_cli_helper_spec.rb b/spec/classes/jenkins_cli_helper_spec.rb index 30db675fa..97e51b079 100644 --- a/spec/classes/jenkins_cli_helper_spec.rb +++ b/spec/classes/jenkins_cli_helper_spec.rb @@ -4,7 +4,6 @@ on_supported_os.each do |os, os_facts| context "on #{os}" do let(:facts) { os_facts } - let(:libdir) { facts[:os]['family'] == 'Debian' ? '/usr/share/jenkins' : '/usr/lib/jenkins' } describe 'relationships' do it do @@ -19,7 +18,7 @@ end it do - is_expected.to contain_file("#{libdir}/puppet_helper.groovy").with( + is_expected.to contain_file('/usr/share/java/puppet_helper.groovy').with( source: 'puppet:///modules/jenkins/puppet_helper.groovy', owner: 'jenkins', group: 'jenkins', diff --git a/spec/classes/jenkins_cli_spec.rb b/spec/classes/jenkins_cli_spec.rb index fb2c3434e..0986e09cb 100644 --- a/spec/classes/jenkins_cli_spec.rb +++ b/spec/classes/jenkins_cli_spec.rb @@ -18,7 +18,7 @@ cli_ssh_keyfile: '/path/to/key', cli_username: 'myuser', libdir: '/path/to/libdir', - config_hash: { 'HTTP_PORT' => { 'value' => '9000' } } } + config_hash: { 'JENKINS_PORT' => { 'value' => '9000' } } } end it { is_expected.to contain_class('jenkins::cli') } @@ -27,7 +27,6 @@ it { is_expected.to contain_exec('reload-jenkins').with_command(%r{-i\s'/path/to/key'}) } it { is_expected.to contain_exec('reload-jenkins').that_requires('File[/path/to/libdir/jenkins-cli.jar]') } it { is_expected.to contain_exec('safe-restart-jenkins') } - it { is_expected.to contain_jenkins__sysconfig('HTTP_PORT').with_value('9000') } describe 'jenkins::cli' do describe 'relationships' do diff --git a/spec/classes/jenkins_config_spec.rb b/spec/classes/jenkins_config_spec.rb index 1c3f314ab..b8355e4eb 100644 --- a/spec/classes/jenkins_config_spec.rb +++ b/spec/classes/jenkins_config_spec.rb @@ -10,31 +10,26 @@ it { is_expected.to contain_class('jenkins::config') } it { is_expected.to contain_jenkins__plugin('credentials') } - expected = case os_facts[:os]['family'] - when 'Debian' - { - 'JAVA_ARGS' => '-Djava.awt.headless=true -Djenkins.install.runSetupWizard=false', - 'AJP_PORT' => '-1' - } - when 'RedHat', 'Suse' - { - 'JENKINS_JAVA_OPTIONS' => '-Djava.awt.headless=true -Djenkins.install.runSetupWizard=false', - 'JENKINS_AJP_PORT' => '-1' - } - else - {} - end - - it { is_expected.to have_jenkins__sysconfig_resource_count(expected.length) } - expected.each do |var, value| - it { is_expected.to contain_jenkins__sysconfig(var).with_value(value) } + it do + is_expected.to contain_file('/etc/systemd/system/jenkins.service.d/puppet-overrides.conf') + .with_content <<~CONFIG + [Service] + Environment="JAVA_OPTS=-Djava.awt.headless=true -Djenkins.install.runSetupWizard=false" + CONFIG end end context 'create config' do let(:params) { { config_hash: { 'AJP_PORT' => { 'value' => '1234' } } } } - it { is_expected.to contain_jenkins__sysconfig('AJP_PORT').with_value('1234') } + it do + is_expected.to contain_file('/etc/systemd/system/jenkins.service.d/puppet-overrides.conf') + .with_content <<~CONFIG + [Service] + Environment="JAVA_OPTS=-Djava.awt.headless=true -Djenkins.install.runSetupWizard=false" + Environment="AJP_PORT=1234" + CONFIG + end end end end diff --git a/spec/classes/jenkins_service_spec.rb b/spec/classes/jenkins_service_spec.rb deleted file mode 100644 index d3211f258..000000000 --- a/spec/classes/jenkins_service_spec.rb +++ /dev/null @@ -1,77 +0,0 @@ -require 'spec_helper' - -describe 'jenkins' do - on_supported_os.each do |os, os_facts| - context "on #{os}", if: os_facts[:osfamily] == 'RedHat' do - let(:facts) { os_facts } - - context 'service' do - let(:service_file) { '/etc/systemd/system/jenkins.service' } - let(:startup_script) { '/usr/lib/jenkins/jenkins-run' } - let(:sysv_file) { '/etc/init.d/jenkins' } - - it { is_expected.to contain_class('jenkins').with_service_provider('systemd') } - it { is_expected.to contain_jenkins__systemd('jenkins') } - - it do - is_expected.to contain_service('jenkins').with( - ensure: 'running', - enable: true, - provider: 'systemd' - ) - end - - it do - is_expected.to contain_file(startup_script). - that_notifies('Service[jenkins]') - end - it do - is_expected.to contain_transition('stop jenkins service'). - with_prior_to(["File[#{sysv_file}]"]) - end - it do - is_expected.to contain_file(sysv_file). - with( - ensure: 'absent', - selinux_ignore_defaults: true - ). - that_comes_before('Systemd::Unit_file[jenkins.service]') - end - it do - is_expected.to contain_systemd__unit_file('jenkins.service'). - that_notifies('Service[jenkins]').with_content(%r{^Type=simple}) - end - - describe 'with jenkins 2.313' do - let(:facts) { super().merge(jenkins_version: '2.313') } - - it do - is_expected.to contain_systemd__unit_file('jenkins.service'). - with_content(%r{^Type=simple}) - end - - it do - is_expected.to contain_file(startup_script).without_content( - %r{^PARAMS\+=\("--daemon"\)} - ) - end - end - - describe 'with jenkins 2.312' do - let(:facts) { super().merge(jenkins_version: '2.312') } - - it do - is_expected.to contain_systemd__unit_file('jenkins.service'). - with_content(%r{^Type=forking}) - end - - it do - is_expected.to contain_file(startup_script).with_content( - %r{^PARAMS\+=\("--daemon"\)} - ) - end - end - end - end - end -end diff --git a/spec/classes/jenkins_spec.rb b/spec/classes/jenkins_spec.rb index 2daf3de1a..bd0e9139d 100755 --- a/spec/classes/jenkins_spec.rb +++ b/spec/classes/jenkins_spec.rb @@ -63,39 +63,6 @@ it { is_expected.not_to contain_class 'jenkins::firewall' } end - describe 'sysconfdir =>' do - var = case os_facts[:os]['family'] - when 'Debian' - 'JAVA_ARGS' - when 'Redhat', 'Suse' - 'JENKINS_JAVA_OPTIONS' - end - - context '/foo/bar', if: var do - let(:params) { { sysconfdir: '/foo/bar' } } - - it do - is_expected.to contain_file_line("Jenkins sysconfig setting #{var}"). - with_path('/foo/bar/jenkins') - end - end - - context '(default)' do - case os_facts[:os]['family'] - when 'Debian' - it do - is_expected.to contain_file_line('Jenkins sysconfig setting JAVA_ARGS'). - with_path('/etc/default/jenkins') - end - when 'RedHat', 'Suse' - it do - is_expected.to contain_file_line('Jenkins sysconfig setting JENKINS_JAVA_OPTIONS'). - with_path('/etc/sysconfig/jenkins') - end - end - end - end - describe 'manage_datadirs =>' do context 'false' do let(:params) { { manage_datadirs: false } } diff --git a/spec/defines/jenkins_cli_exec_spec.rb b/spec/defines/jenkins_cli_exec_spec.rb index 85c80f0f5..94b271422 100644 --- a/spec/defines/jenkins_cli_exec_spec.rb +++ b/spec/defines/jenkins_cli_exec_spec.rb @@ -6,8 +6,7 @@ on_supported_os.each do |os, os_facts| context "on #{os}" do let(:facts) { os_facts } - let(:libdir) { facts[:os]['family'] == 'Debian' ? '/usr/share/jenkins' : '/usr/lib/jenkins' } - let(:helper_cmd) { "/bin/cat #{libdir}/puppet_helper.groovy | /usr/bin/java -jar #{libdir}/jenkins-cli.jar -s http://127.0.0.1:8080 groovy =" } + let(:helper_cmd) { "/bin/cat /usr/share/java/puppet_helper.groovy | /usr/bin/java -jar /usr/share/java/jenkins-cli.jar -s http://127.0.0.1:8080 groovy =" } describe 'relationships' do it do diff --git a/spec/defines/jenkins_sysconfig_spec.rb b/spec/defines/jenkins_sysconfig_spec.rb deleted file mode 100644 index 216a464f8..000000000 --- a/spec/defines/jenkins_sysconfig_spec.rb +++ /dev/null @@ -1,36 +0,0 @@ -require 'spec_helper' - -describe 'jenkins::sysconfig' do - let(:pre_condition) { 'include jenkins' } - let(:title) { 'myprop' } - let(:params) { { 'value' => 'myvalue' } } - - on_supported_os.each do |os, os_facts| - context "on #{os} " do - let(:facts) { os_facts } - - case os_facts[:os]['family'] - when 'RedHat' - describe 'on RedHat' do - it do - is_expected.to contain_file_line('Jenkins sysconfig setting myprop').with( - path: '/etc/sysconfig/jenkins', - line: 'myprop="myvalue"', - match: '^myprop=' - ).that_notifies('Service[jenkins]') - end - end - when 'Debian' - describe 'on Debian' do - it do - is_expected.to contain_file_line('Jenkins sysconfig setting myprop').with( - path: '/etc/default/jenkins', - line: 'myprop="myvalue"', - match: '^myprop=' - ).that_notifies('Service[jenkins]') - end - end - end - end - end -end diff --git a/spec/functions/jenkins_port_spec.rb b/spec/functions/jenkins_port_spec.rb index 299604953..1ce1fb6cd 100644 --- a/spec/functions/jenkins_port_spec.rb +++ b/spec/functions/jenkins_port_spec.rb @@ -19,7 +19,7 @@ let(:pre_condition) do <<-ENDPUPPET class { 'jenkins': - config_hash => {'HTTP_PORT' => {'value' => '1337'}}, + config_hash => {'JENKINS_PORT' => {'value' => '1337'}}, } ENDPUPPET end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index bef664697..a7f385d5a 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -8,34 +8,6 @@ require 'voxpupuli/test/spec_helper' -# Rough conversion of grepping in the puppet source: -# grep defaultfor lib/puppet/provider/service/*.rb -add_custom_fact(:service_provider, lambda do |_os, facts| - case facts[:os]['family'].downcase - when 'archlinux' - 'systemd' - when 'darwin' - 'launchd' - when 'debian' - 'systemd' - when 'freebsd' - 'freebsd' - when 'gentoo' - 'openrc' - when 'openbsd' - 'openbsd' - when 'redhat' - facts[:operatingsystemrelease].to_i >= 7 ? 'systemd' : 'redhat' - when 'suse' - facts[:operatingsystemmajrelease].to_i >= 12 ? 'systemd' : 'redhat' - when 'windows' - 'windows' - else - 'init' - end -end) -add_custom_fact :systemd, ->(_os, facts) { facts['service_provider'] == 'systemd' } - if File.exist?(File.join(__dir__, 'default_module_facts.yml')) facts = YAML.safe_load(File.read(File.join(__dir__, 'default_module_facts.yml'))) if facts diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb index 9cc725432..f228ff069 100644 --- a/spec/spec_helper_acceptance.rb +++ b/spec/spec_helper_acceptance.rb @@ -4,14 +4,6 @@ shared_context 'jenkins' do # rspec examples are not available as variables to serverspec describe blocks - LIBDIR = case fact 'osfamily' - when 'RedHat' - '/usr/lib/jenkins' - when 'Debian' - '/usr/share/jenkins' - when 'Archlinux' - '/usr/share/java/jenkins/' - end SYSCONFDIR = case fact 'osfamily' when 'RedHat' '/etc/sysconfig' @@ -20,18 +12,6 @@ when 'Archlinux' '/etc/conf.d' end - - let(:libdir) { LIBDIR } - - let(:base_manifest) do - <<-EOS - include jenkins - class { 'jenkins::cli::config': - cli_jar => '#{libdir}/jenkins-cli.jar', - puppet_helper => '#{libdir}/puppet_helper.groovy', - } - EOS - end end def apply(pp, options = {}) @@ -56,14 +36,3 @@ def apply2(pp) on(hosts, 'facter --json jenkins_plugins') end end - -# probe stolen from: -# https://github.com/camptocamp/puppet-systemd/blob/master/lib/facter/systemd.rb#L26 -# -# See these issues for an explination of why this is nessicary rather than -# using fact() from beaker-facter in the DSL: -# -# https://tickets.puppetlabs.com/browse/BKR-1040 -# https://tickets.puppetlabs.com/browse/BKR-1041 -# -SYSTEMD = shell('ps -p 1 -o comm=').stdout =~ %r{systemd} diff --git a/spec/unit/puppet/x/jenkins/config_spec.rb b/spec/unit/puppet/x/jenkins/config_spec.rb index f6b836742..62412425f 100644 --- a/spec/unit/puppet/x/jenkins/config_spec.rb +++ b/spec/unit/puppet/x/jenkins/config_spec.rb @@ -4,10 +4,10 @@ describe Puppet::X::Jenkins::Config do DEFAULTS = { - cli_jar: '/usr/lib/jenkins/jenkins-cli.jar', + cli_jar: '/usr/share/java/jenkins-cli.jar', url: 'http://localhost:8080', ssh_private_key: nil, - puppet_helper: '/usr/lib/jenkins/puppet_helper.groovy', + puppet_helper: '/usr/share/java/puppet_helper.groovy', cli_tries: 30, cli_try_sleep: 2 }.freeze diff --git a/spec/unit/puppet/x/jenkins/provider/cli_spec.rb b/spec/unit/puppet/x/jenkins/provider/cli_spec.rb index 32ee742b3..79cb2e125 100644 --- a/spec/unit/puppet/x/jenkins/provider/cli_spec.rb +++ b/spec/unit/puppet/x/jenkins/provider/cli_spec.rb @@ -223,7 +223,7 @@ expect(described_class).to receive(:cli).with( ['groovy', '=', 'foo'], { tmpfile_as_param: true }, - ['/bin/cat', '/usr/lib/jenkins/puppet_helper.groovy', '|'] + ['/bin/cat', '/usr/share/java/puppet_helper.groovy', '|'] ) described_class.clihelper('foo') @@ -324,7 +324,7 @@ shared_examples 'uses default values' do it 'uses default values' do expect(described_class.superclass).to receive(:execute).with( - 'java -jar /usr/lib/jenkins/jenkins-cli.jar -s http://localhost:8080 -logger WARNING foo', + 'java -jar /usr/share/java/jenkins-cli.jar -s http://localhost:8080 -logger WARNING foo', failonfail: true, combine: true ) @@ -422,7 +422,7 @@ CLI_AUTH_ERRORS.each do |error| it 'does not retry cli on AuthError exception' do expect(described_class.superclass).to receive(:execute).with( - 'java -jar /usr/lib/jenkins/jenkins-cli.jar -s http://localhost:8080 -logger WARNING foo', + 'java -jar /usr/share/java/jenkins-cli.jar -s http://localhost:8080 -logger WARNING foo', failonfail: true, combine: true ).and_raise(AuthError, error) @@ -447,7 +447,7 @@ it 'tries cli without auth first' do expect(described_class.superclass).to receive(:execute).with( - 'java -jar /usr/lib/jenkins/jenkins-cli.jar -s http://localhost:8080 -logger WARNING foo', + 'java -jar /usr/share/java/jenkins-cli.jar -s http://localhost:8080 -logger WARNING foo', failonfail: true, combine: true ) @@ -457,12 +457,12 @@ CLI_AUTH_ERRORS.each do |error| it 'retries cli on AuthError exception' do expect(described_class.superclass).to receive(:execute).with( - 'java -jar /usr/lib/jenkins/jenkins-cli.jar -s http://localhost:8080 -logger WARNING foo', + 'java -jar /usr/share/java/jenkins-cli.jar -s http://localhost:8080 -logger WARNING foo', failonfail: true, combine: true ).and_raise(AuthError, error) expect(described_class.superclass).to receive(:execute).with( - 'java -jar /usr/lib/jenkins/jenkins-cli.jar -s http://localhost:8080 -logger WARNING -i cat.id_rsa -ssh -user myuser foo', + 'java -jar /usr/share/java/jenkins-cli.jar -s http://localhost:8080 -logger WARNING -i cat.id_rsa -ssh -user myuser foo', failonfail: true, combine: true ) @@ -470,12 +470,12 @@ # and it should remember that auth is required expect(described_class.superclass).not_to receive(:execute).with( - 'java -jar /usr/lib/jenkins/jenkins-cli.jar -s http://localhost:8080 -logger WARNING foo', + 'java -jar /usr/share/java/jenkins-cli.jar -s http://localhost:8080 -logger WARNING foo', failonfail: true, combine: true ) expect(described_class.superclass).to receive(:execute).with( - 'java -jar /usr/lib/jenkins/jenkins-cli.jar -s http://localhost:8080 -logger WARNING -i cat.id_rsa -ssh -user myuser foo', + 'java -jar /usr/share/java/jenkins-cli.jar -s http://localhost:8080 -logger WARNING -i cat.id_rsa -ssh -user myuser foo', failonfail: true, combine: true ) @@ -490,7 +490,7 @@ CLI_NET_ERRORS.each do |error| it 'does not retry cli on AuthError exception' do expect(described_class.superclass).to receive(:execute).with( - 'java -jar /usr/lib/jenkins/jenkins-cli.jar -s http://localhost:8080 -logger WARNING foo', + 'java -jar /usr/share/java/jenkins-cli.jar -s http://localhost:8080 -logger WARNING foo', failonfail: true, combine: true ).exactly(30).times.and_raise(NetError, error) @@ -513,7 +513,7 @@ catalog.add_resource jenkins expect(described_class.superclass).to receive(:execute).with( - 'java -jar /usr/lib/jenkins/jenkins-cli.jar -s http://localhost:8080 -logger WARNING foo', + 'java -jar /usr/share/java/jenkins-cli.jar -s http://localhost:8080 -logger WARNING foo', failonfail: true, combine: true ).exactly(30).times.and_raise(UnknownError, 'foo') @@ -529,7 +529,7 @@ catalog.add_resource jenkins expect(described_class.superclass).to receive(:execute).with( - 'java -jar /usr/lib/jenkins/jenkins-cli.jar -s http://localhost:8080 -logger WARNING foo', + 'java -jar /usr/share/java/jenkins-cli.jar -s http://localhost:8080 -logger WARNING foo', failonfail: true, combine: true ).exactly(2).times.and_raise(UnknownError, 'foo') @@ -546,7 +546,7 @@ catalog.add_resource jenkins expect(described_class.superclass).to receive(:execute).with( - 'java -jar /usr/lib/jenkins/jenkins-cli.jar -s http://localhost:8080 -logger WARNING foo', + 'java -jar /usr/share/java/jenkins-cli.jar -s http://localhost:8080 -logger WARNING foo', failonfail: true, combine: true ).exactly(3).times.and_raise(UnknownError, 'foo') @@ -564,7 +564,7 @@ catalog.add_resource jenkins expect(described_class.superclass).to receive(:execute).with( - 'java -jar /usr/lib/jenkins/jenkins-cli.jar -s http://localhost:8080 -logger WARNING foo', + 'java -jar /usr/share/java/jenkins-cli.jar -s http://localhost:8080 -logger WARNING foo', failonfail: true, combine: true ).exactly(2).times.and_raise(UnknownError, 'foo') @@ -661,7 +661,7 @@ expect(tmp).to receive(:path) { '/dne.tmp' } expect(described_class.superclass).to receive(:execute).with( - 'java -jar /usr/lib/jenkins/jenkins-cli.jar -s http://localhost:8080 -logger WARNING foo', + 'java -jar /usr/share/java/jenkins-cli.jar -s http://localhost:8080 -logger WARNING foo', failonfail: true, combine: true, stdinfile: '/dne.tmp' @@ -683,7 +683,7 @@ expect(tmp).to receive(:path) { '/dne.tmp' } expect(described_class.superclass).to receive(:execute).with( - 'java -jar /usr/lib/jenkins/jenkins-cli.jar -s http://localhost:8080 -logger WARNING foo', + 'java -jar /usr/share/java/jenkins-cli.jar -s http://localhost:8080 -logger WARNING foo', failonfail: true, combine: true, stdinfile: '/dne.tmp' diff --git a/templates/jenkins-override.epp b/templates/jenkins-override.epp new file mode 100644 index 000000000..120162e1c --- /dev/null +++ b/templates/jenkins-override.epp @@ -0,0 +1,5 @@ +<%| Hash[String, Struct[{value => Any}]] $environment |-%> +[Service] +<% $environment.each |$key, $entry| { -%> +Environment="<%= $key %>=<%= $entry['value'] %>" +<% } -%> diff --git a/templates/jenkins-run.erb b/templates/jenkins-run.erb deleted file mode 100644 index 4f60666dd..000000000 --- a/templates/jenkins-run.erb +++ /dev/null @@ -1,80 +0,0 @@ -#!/bin/bash - -# taken from -# https://github.com/jenkinsci/packaging/blob/master/rpm/build/SOURCES/jenkins.init.in -# and modified for usage under systemd - -# -# SUSE system statup script for Jenkins -# Copyright (C) 2007 Pascal Bleser -# -# This library is free software; you can redistribute it and/or modify it -# under the terms of the GNU Lesser General Public License as published by -# the Free Software Foundation; either version 2.1 of the License, or (at -# your option) any later version. -# -# This library is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, -# USA. -# - -# Check for missing binaries (stale symlinks should not happen) -# XXX JENKINS_WAR is currently in the Debian sysconf but not on RedHat -# fix this upstream -JENKINS_WAR=${JENKINS_WAR:-<%= scope['jenkins::libdir'] %>/jenkins.war} -test -r "$JENKINS_WAR" || { echo "$JENKINS_WAR not installed"; exit 5; } - -# Set up environment accordingly to the configuration settings -[ -n "$JENKINS_HOME" ] || { echo "JENKINS_HOME not configured "; exit 6; } -[ -d "$JENKINS_HOME" ] || { echo "JENKINS_HOME directory does not exist: $JENKINS_HOME"; exit 1; } - -# this should work for both RedHat and Debian -# Search usable Java as /usr/bin/java might not point to minimal version required by Jenkins. -candidates=" -/etc/alternatives/java -/usr/lib/jvm/java-1.8.0/bin/java -/usr/lib/jvm/jre-1.8.0/bin/java -/usr/lib/jvm/java-1.7.0/bin/java -/usr/lib/jvm/jre-1.7.0/bin/java -/usr/bin/java -" -for candidate in $candidates -do - [ -x "$JENKINS_JAVA_CMD" ] && break - JENKINS_JAVA_CMD="$candidate" -done - -JAVA_CMD="$JENKINS_JAVA_CMD $JENKINS_JAVA_OPTIONS -DJENKINS_HOME=$JENKINS_HOME -jar $JENKINS_WAR" - -PARAMS=() -PARAMS+=("--logfile=/var/log/jenkins/jenkins.log") -PARAMS+=("--webroot=/var/cache/jenkins/war") -<%- if scope['jenkins::systemd_type'] == 'forking' -%> -PARAMS+=("--daemon") -<%- end -%> - -[ -n "$JENKINS_PORT" ] && PARAMS+=("--httpPort=$JENKINS_PORT") -[ -n "$JENKINS_LISTEN_ADDRESS" ] && PARAMS+=("--httpListenAddress=$JENKINS_LISTEN_ADDRESS") -[ -n "$JENKINS_HTTPS_PORT" ] && PARAMS+=("--httpsPort=$JENKINS_HTTPS_PORT") -[ -n "$JENKINS_HTTPS_KEYSTORE" ] && PARAMS+=("--httpsKeyStore=$JENKINS_HTTPS_KEYSTORE") -[ -n "$JENKINS_HTTPS_KEYSTORE_PASSWORD" ] && PARAMS+=("--httpsKeyStorePassword="$JENKINS_HTTPS_KEYSTORE_PASSWORD"") -[ -n "$JENKINS_HTTPS_LISTEN_ADDRESS" ] && PARAMS+=("--httpsListenAddress=$JENKINS_HTTPS_LISTEN_ADDRESS") -[ -n "$JENKINS_DEBUG_LEVEL" ] && PARAMS+=("--debug=$JENKINS_DEBUG_LEVEL") -[ -n "$JENKINS_HANDLER_STARTUP" ] && PARAMS+=("--handlerCountStartup=$JENKINS_HANDLER_STARTUP") -[ -n "$JENKINS_HANDLER_MAX" ] && PARAMS+=("--handlerCountMax=$JENKINS_HANDLER_MAX") -[ -n "$JENKINS_HANDLER_IDLE" ] && PARAMS+=("--handlerCountMaxIdle=$JENKINS_HANDLER_IDLE") -[ -n "$JENKINS_ARGS" ] && PARAMS+=("$JENKINS_ARGS") - -if [ "$JENKINS_ENABLE_ACCESS_LOG" = "yes" ]; then - PARAMS+=("--accessLoggerClassName=winstone.accesslog.SimpleAccessLogger") - PARAMS+=("--simpleAccessLogger.format=combined") - PARAMS+=("--simpleAccessLogger.file=/var/log/jenkins/access_log") -fi - -$JAVA_CMD "${PARAMS[@]}" diff --git a/templates/jenkins.service.erb b/templates/jenkins.service.erb deleted file mode 100644 index ea7c25cd8..000000000 --- a/templates/jenkins.service.erb +++ /dev/null @@ -1,15 +0,0 @@ -[Unit] -Description=Jenkins master service -Requires=network.target -After=network.target - -[Service] -Type=<%= scope['jenkins::systemd_type'] %> -User=<%= scope['jenkins::user'] %> -Group=<%= scope['jenkins::group'] %> -EnvironmentFile=<%= scope['jenkins::sysconfdir'] %>/jenkins -ExecStart=<%= scope['jenkins::libdir'] %>/jenkins-run -Restart=always - -[Install] -WantedBy=multi-user.target