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“, “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.
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 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 |
# File 'manifests/init.pp', line 293
class jenkins(
String $version = $jenkins::params::version,
Boolean $lts = $jenkins::params::lts,
Boolean $repo = $jenkins::params::repo,
String $package_name = $jenkins::params::package_name,
Optional[String] $direct_download = $jenkins::params::direct_download,
Stdlib::Absolutepath $package_cache_dir = $jenkins::params::package_cache_dir,
Optional[String] $package_provider = $jenkins::params::package_provider,
Boolean $manage_service = true,
Boolean $service_enable = $jenkins::params::service_enable,
Enum['running', 'stopped'] $service_ensure = $jenkins::params::service_ensure,
Optional[String] $service_provider = $jenkins::params::service_provider,
Hash $config_hash = {},
Hash $plugin_hash = {},
Hash $job_hash = {},
Hash $user_hash = {},
Boolean $configure_firewall = false,
Boolean $install_java = $jenkins::params::install_java,
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,
Optional[Boolean] $cli_remoting_free = undef,
Integer $cli_tries = $jenkins::params::cli_tries,
Integer $cli_try_sleep = $jenkins::params::cli_try_sleep,
Integer $port = $jenkins::params::port,
Stdlib::Absolutepath $libdir = $jenkins::params::libdir,
Stdlib::Absolutepath $sysconfdir = $jenkins::params::sysconfdir,
Boolean $manage_datadirs = $jenkins::params::manage_datadirs,
Stdlib::Absolutepath $localstatedir = $::jenkins::params::localstatedir,
Optional[Integer] $executors = undef,
Optional[Integer] $slaveagentport = undef,
Boolean $manage_user = $::jenkins::params::manage_user,
String $user = $::jenkins::params::user,
Boolean $manage_group = $::jenkins::params::manage_group,
String $group = $::jenkins::params::group,
Array $default_plugins = $::jenkins::params::default_plugins,
String $default_plugins_host = $::jenkins::params::default_plugins_host,
Boolean $purge_plugins = $::jenkins::params::purge_plugins,
) inherits jenkins::params {
if $purge_plugins and ! $manage_datadirs {
warning('jenkins::purge_plugins has no effect unless jenkins::manage_datadirs is true')
}
## determine if we must use the new CLI
if $cli_remoting_free == undef {
notice("INFO: Using the automatic detection of new cli mode (See https://issues.jenkins-ci.org/browse/JENKINS-41745), use \$::jenkins::cli_remoting_free=(true|false) to enable or disable explicitly")
# Heuristics (default)
# We try to "guess" if a new CLI version of jenkins is
# in use. If we can be sure, we enable new CLI mode automatically.
# If not, we keep the old way and print a hint about
# the explicit mode (this is true for custom repo setups,
# that do not mirror the Jenkins repo, but release jenkins
# versions based on repo stages and not pinning in puppet)
if $repo {
if $lts {
# we use a LTS version, so new cli is included in 2.46.2
if $version == 'latest' {
$_use_new_cli = true
} elsif $version == 'installed' {
$_use_new_cli = false
} elsif $version =~ /\d+\.\d+/ and versioncmp($version,'2.46.2') >= 0 {
$_use_new_cli = true
} else {
$_use_new_cli = false
}
} else {
# we use a regular version, so new cli is included in 2.54
if $version == 'latest' {
$_use_new_cli = true
} elsif $version == 'installed' {
$_use_new_cli = false
} elsif $version =~ /\d+\.\d+/ and versioncmp($version,'2.54') >= 0 {
$_use_new_cli = true
} else {
$_use_new_cli = false
}
}
} else {
# Repo not managed, so we do not know if it is a LTS or regular version
if $version =~ /\d+\.\d+/ and versioncmp($version,'2.54') >= 0 {
$_use_new_cli = true
} else {
$_use_new_cli = false
}
}
} else {
$_use_new_cli = str2bool($cli_remoting_free)
}
# Construct the cli auth argument used in cli and cli_helper
if $cli_ssh_keyfile {
# SSH key auth
if $_use_new_cli {
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}'"
} else {
$_cli_auth_arg = "-i '${cli_ssh_keyfile}'"
}
} elsif !empty($cli_username) {
# Username / Password auth (needed for AD and other Auth Realms)
if $_use_new_cli {
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 {
fail('ERROR: Due to https://issues.jenkins-ci.org/browse/JENKINS-12543 username and password mode are only supported for the non-remoting CLI mode (see https://issues.jenkins-ci.org/browse/JENKINS-41745)')
}
} else {
# default = no auth
$_cli_auth_arg = undef
}
$plugin_dir = "${localstatedir}/plugins"
$job_dir = "${localstatedir}/jobs"
anchor {'jenkins::begin':}
anchor {'jenkins::end':}
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::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
}
}
if defined('::firewall') {
if $configure_firewall == undef {
fail('The firewall module is included in your manifests, please configure $configure_firewall in the jenkins module')
} elsif $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_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']
}
if $service_provider == 'systemd' {
jenkins::systemd { 'jenkins':
user => $user,
libdir => $libdir,
}
# 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']
}
}
|