Puppet Class: jenkins
- Inherits:
- jenkins::params
- Defined in:
- manifests/init.pp
Overview
This class manages the [Jenkins CI/CD service](jenkins.io/index.html).
Note that if different jenkins listening port(s) are configured via “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.
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 |
# File 'manifests/init.pp', line 276
class jenkins (
String $version = 'installed',
Boolean $lts = true,
Boolean $repo = $jenkins::params::repo,
String $package_name = 'jenkins',
Optional[String] $direct_download = undef,
Stdlib::Absolutepath $package_cache_dir = '/var/cache/jenkins_pkgs',
Optional[String] $package_provider = $jenkins::params::package_provider,
Boolean $manage_service = true,
Boolean $service_enable = true,
Enum['running', 'stopped'] $service_ensure = 'running',
Hash[String[1], String] $service_override = {},
Optional[String] $service_provider = undef,
Hash $config_hash = {},
Hash $plugin_hash = {},
Hash $job_hash = {},
Hash $user_hash = {},
Boolean $configure_firewall = false,
Boolean $install_java = true,
Optional[String] $repo_proxy = undef,
Optional[String] $proxy_host = undef,
Optional[Integer] $proxy_port = undef,
Optional[Array] $no_proxy_list = undef,
Boolean $cli = true,
Optional[Stdlib::Absolutepath] $cli_ssh_keyfile = undef,
Optional[String] $cli_username = undef,
Optional[String] $cli_password = undef,
Optional[String] $cli_password_file = undef,
Integer $cli_tries = 10,
Integer $cli_try_sleep = 10,
Integer $port = 8080,
Stdlib::Absolutepath $libdir = '/usr/share/java',
Boolean $manage_datadirs = true,
Stdlib::Absolutepath $localstatedir = '/var/lib/jenkins',
Optional[Integer] $executors = undef,
Optional[Integer] $slaveagentport = undef,
Boolean $manage_user = true,
String $user = 'jenkins',
Boolean $manage_group = true,
String $group = 'jenkins',
Array $default_plugins = $jenkins::params::default_plugins,
String $default_plugins_host = 'https://updates.jenkins.io',
Boolean $purge_plugins = false,
) inherits jenkins::params {
if $purge_plugins and ! $manage_datadirs {
warning('jenkins::purge_plugins has no effect unless jenkins::manage_datadirs is true')
}
# Construct the cli auth argument used in cli and cli_helper
if $cli_ssh_keyfile {
# SSH key auth
if empty($cli_username) {
fail('ERROR: Latest remoting free CLI (see https://issues.jenkins-ci.org/browse/JENKINS-41745) needs username for SSH Access (\$jenkins::cli_username)')
}
$_cli_auth_arg = "-i '${cli_ssh_keyfile}' -ssh -user '${cli_username}'"
} elsif !empty($cli_username) {
# Username / Password auth (needed for AD and other Auth Realms)
if !empty($cli_password) {
$_cli_auth_arg = "-auth '${cli_username}:${cli_password}'"
} elsif !empty($cli_password_file) {
$_cli_auth_arg = "-auth '@${cli_password_file}'"
} else {
fail('ERROR: Need cli_password or cli_password_file if cli_username is specified')
}
} else {
# default = no auth
$_cli_auth_arg = undef
}
$plugin_dir = "${localstatedir}/plugins"
$job_dir = "${localstatedir}/jobs"
# lint:ignore:anchor_resource
anchor { 'jenkins::begin': }
anchor { 'jenkins::end': }
# lint:endignore
if $install_java {
include java
}
if $direct_download {
$repo_ = false
$jenkins_package_class = 'jenkins::direct_download'
} else {
$jenkins_package_class = 'jenkins::package'
if $repo {
$repo_ = true
include jenkins::repo
} else {
$repo_ = false
}
}
include $jenkins_package_class
include jenkins::user_setup
include jenkins::config
include jenkins::plugins
include jenkins::jobs
include jenkins::users
include jenkins::proxy
if $manage_service {
include jenkins::service
if empty($default_plugins) {
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
}
# 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,
}
file { '/etc/systemd/system/jenkins.service':
ensure => absent,
notify => Service['jenkins'],
}
}
if defined('::firewall') and $configure_firewall {
include jenkins::firewall
}
if $cli {
include jenkins::cli
include jenkins::cli_helper
}
if $executors {
jenkins::cli::exec { 'set_num_executors':
command => ['set_num_executors', $executors],
unless => "[ \$(\$HELPER_CMD get_num_executors) -eq ${executors} ]",
}
Class['jenkins::cli']
-> Jenkins::Cli::Exec['set_num_executors']
-> Class['jenkins::jobs']
}
if ($slaveagentport != undef) {
jenkins::cli::exec { 'set_slaveagent_port':
command => ['set_slaveagent_port', $slaveagentport],
unless => "[ \$(\$HELPER_CMD get_slaveagent_port) -eq ${slaveagentport} ]",
}
Class['jenkins::cli']
-> Jenkins::Cli::Exec['set_slaveagent_port']
-> Class['jenkins::jobs']
}
if $manage_service {
Anchor['jenkins::begin']
-> Class['jenkins::user_setup']
-> Class[$jenkins_package_class]
-> Class['jenkins::config']
-> Class['jenkins::plugins']
~> Class['jenkins::service']
-> Class['jenkins::jobs']
-> Anchor['jenkins::end']
}
if $install_java {
Anchor['jenkins::begin']
-> Class['java']
-> Class[$jenkins_package_class]
-> Anchor['jenkins::end']
}
if $repo_ {
Anchor['jenkins::begin']
-> Class['jenkins::repo']
-> Class['jenkins::package']
-> Anchor['jenkins::end']
}
if ($configure_firewall and $manage_service) {
Class['jenkins::service']
-> Class['jenkins::firewall']
-> Anchor['jenkins::end']
}
}
|