As a software tester you need a test environment! The test environment should be soon as possible and without outside resources deployable. This guide shows you how to install Jenkins on Debian/Ubuntu with Puppet (Version 2.7.x).
Preparation
# get puppet version
$ puppet --version
# get puppet-lint version
$ puppet-lint --version
If Puppet and Puppet-Lint are not installed:
# update and upgrade
$ apt-get update && apt-get upgrade
# install puppet and puppet-lint
$ apt-get install puppet && apt-get install puppet-lint
The project looks like the following:
testenvironment
├── manifests
│ ├── nodes.pp
│ └── site.pp
└── modules
└── jenkins
└── manifests
└── init.pp
Steps
# create folders
$ mkdir -p testenvironment/manifests
$ mkdir -p testenvironment/modules/jenkins/manifests
# create files
$ touch testenvironment/manifests/site.pp
$ touch testenvironment/manifests/nodes.pp
$ touch testenvironment/modules/jenkins/manifests/init.pp
The first content we add is for “site.pp”. Here we include the “nodes.pp” and setup basic paths.
import 'nodes.pp'
Exec {
path => ['/bin', '/usr/bin'],
}
The next content is for second file “nodes.pp”. Here we create the case statement with the include for Jenkins class and a message (if OS is not supported).
node default {
case $::operatingsystem {
'Debian', 'Ubuntu' : { include jenkins }
default : { notify {"$::operatingsystem is not supported yet":} }
}
}
As last step we create the content for “init.pp”.
class jenkins {
# get key
exec { 'install_jenkins_key':
command => 'wget -q -O - http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key | apt-key add - ',
}
# update
exec { 'apt-get update':
command => 'apt-get update',
require => File['/etc /apt/sources.list.d/jenkins.list'],
}
# source file
file { '/etc /apt/sources.list.d/jenkins.list':
content => "deb http://pkg.jenkins-ci.org/debian binary/\n",
mode => '0644',
owner => root,
group => root,
require => Exec['install_jenkins_key'],
}
# jenkins package
package { 'jenkins':
ensure => latest,
require => Exec['apt-get update'],
}
# jenkins service
service { 'jenkins':
ensure => running,
require => Package['jenkins'],
}
}
Note: The space after “/etc /apt” on “update” and “source file” should removed! I made this just because of the security policies of my provider. They do not allow! 🙁
Continue
First we check the syntax with the puppet-lint. As software tester i think you always lint! 😉
# example project-wide
$ puppet-lint testenvironment/
# example specific files
$ puppet-lint testenvironment/manifests/site.pp
$ puppet-lint testenvironment/manifests/nodes.pp
$ puppet-lint testenvironment/modules/jenkins/manifests/init.pp
Now we make some different “Dry-runs”.
# simple Dry-run with noop
$ puppet apply testenvironment/manifests/site.pp --modulepath=/root/testenvironment/modules/ $* --noop
# Dry-run with noop and summarize
$ puppet apply testenvironment/manifests/site.pp --modulepath=/root/testenvironment/modules/ $* --noop --summarize
# Dry-run with noop, summarize and debug
$ puppet apply testenvironment/manifests/site.pp --modulepath=/root/testenvironment/modules/ $* --noop --summarize --debug
With “–noop” nothing is really executed. The “–modulepath”, “–summarize” and “–debug” speaks for themselves.
the Final
Now the final, after the Puppet is ready you should able to connect to Jenkins.
# run puppet
$ puppet apply testenvironment/manifests/site.pp --modulepath=/root/testenvironment/modules/ $*