Puppet Class: psick::jenkins::scm_sync

Defined in:
manifests/jenkins/scm_sync.pp

Summary

Installs and configures SCM Sync plugin

Overview

This class is automatically loaded if it’s set psick::jenkins::scm_sync_repository_url

Parameters:

  • ensure (Variant[Boolean,String]) (defaults to: 'present')

    If the enable or not the plugin

  • config_template (String) (defaults to: 'psick/jenkins/scm_sync/scm-sync-configuration.xml.erb')

    Template to use for scm-sync-configuration.xml

  • repository_url (Optional[String]) (defaults to: $::psick::jenkins::scm_sync_repository_url)

    Url of the git repo to sync where Jenkins configs are saved

  • service_reload_command

    Command to execute to trigger Jenkins reload Possible alternative: “curl -X POST 127.0.0.1:8080/reload -u admin:$(cat ‘secrets/initialAdminPassword’)” For details: github.com/jenkinsci/scm-sync-configuration-plugin/issues/44

  • jenkins_reload_command (String) (defaults to: 'service jenkins force-reload')


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
# File 'manifests/jenkins/scm_sync.pp', line 13

class psick::jenkins::scm_sync (
  Variant[Boolean,String] $ensure  = 'present',
  String $config_template = 'psick/jenkins/scm_sync/scm-sync-configuration.xml.erb',
  String $jenkins_reload_command   = 'service jenkins force-reload',
  Optional[String] $repository_url = $::psick::jenkins::scm_sync_repository_url,
) {

  if !defined(Psick::Jenkins::Plugin['scm-sync-configuration']) {
    $plugin_enable = $ensure ? {
      'absent' => false,
      default  => true,
    }
    psick::jenkins::plugin { 'scm-sync-configuration':
      enable   => $plugin_enable,
    }
  }
  if $config_template != '' and $repository_url {
    file { "${::psick::jenkins::home_dir}/scm-sync-configuration.xml" :
      ensure  => $ensure,
      mode    => '0644',
      owner   => 'jenkins',
      group   => 'jenkins',
      notify  => Service['jenkins'],
      replace => false,
      content => template($config_template),
      require => Package['jenkins'],
    }
  }

  if $repository_url {
    # Trigger scm sync
    exec { 'trigger_jenkins_scm_sync' :
      command => "sleep 5 ; curl http://127.0.0.1:8080/plugin/scm-sync-configuration/reloadAllFilesFromScm -u admin:\$(cat 'secrets/initialAdminPassword')",
      cwd     => $::psick::jenkins::home_dir,
      creates => "${::psick::jenkins::home_dir}/scm-sync-configuration.success.log",
      require => [ File["${::psick::jenkins::home_dir}/scm-sync-configuration.xml"], Service['jenkins'] ],
      user    => 'jenkins',
      notify  => Exec['jenkins_reload'],
    }
    exec { 'jenkins_reload' :
      command     => $jenkins_reload_command,
      cwd         => $::psick::jenkins::home_dir,
      require     => [ File["${::psick::jenkins::home_dir}/scm-sync-configuration.xml"], Service['jenkins'] ],
      refreshonly => true,
    }
  }
}