├── .gitignore ├── .kitchen.yml ├── Berksfile ├── Gemfile ├── README.md ├── chefignore ├── circle.yml ├── cookbooks └── jenkins-config │ ├── attributes │ ├── default.rb │ ├── java.rb │ ├── jenkins-plugins.rb │ └── prereqs.rb │ ├── files │ └── default │ │ └── etc-profile-d-homebin.sh │ ├── metadata.rb │ ├── recipes │ ├── default.rb │ ├── homebin.rb │ ├── jenkins-auth.rb │ ├── jenkins-jobs.rb │ ├── jenkins-plugins.rb │ ├── master.rb │ ├── prereqs.rb │ ├── slave.rb │ └── update-plugins.rb │ └── templates │ └── job-seed.xml.erb ├── jenkins.json ├── packer-build.sh └── test └── integration └── default └── serverspec ├── Gemfile ├── http_type.rb ├── jenkins_plugins_spec.rb ├── jenkins_service_spec.rb └── spec_helper.rb /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled source # 2 | ################### 3 | *.com 4 | *.class 5 | *.dll 6 | *.exe 7 | *.o 8 | *.so 9 | *.lock 10 | 11 | # Packages # 12 | ############ 13 | # it's better to unpack these files and commit the raw source 14 | # git has its own built in compression methods 15 | *.7z 16 | *.dmg 17 | *.gz 18 | *.iso 19 | *.jar 20 | *.rar 21 | *.tar 22 | *.zip 23 | 24 | # Logs and databases # 25 | ###################### 26 | *.log 27 | *.sql 28 | *.sqlite 29 | 30 | # OS generated files # 31 | ###################### 32 | .DS_Store 33 | .DS_Store? 34 | ._* 35 | .Spotlight-V100 36 | .Trashes 37 | ehthumbs.db 38 | Thumbs.db 39 | .kitchen/ 40 | .kitchen.local.yml 41 | 42 | # Berksshelf cache 43 | .berkscache 44 | -------------------------------------------------------------------------------- /.kitchen.yml: -------------------------------------------------------------------------------- 1 | --- 2 | driver: 3 | name: ec2 4 | require_chef_omnibus: true 5 | instance_type: m4.large 6 | region: us-east-1 7 | aws_ssh_key_id: <%= ENV['TOPHAT_EC2_KEY'] %> 8 | security_group_ids: <%= ENV['TOPHAT_SG'] %> 9 | subnet_id: <%= ENV['TOPHAT_SUBNET_ID'] %> 10 | tags: 11 | Name: jenkins-test-kitchen 12 | owner: <%= ENV['USER'] %> 13 | associate_public_ip: true 14 | 15 | provisioner: 16 | name: chef_solo 17 | cookbooks_path: 18 | - ./cookbooks 19 | 20 | platforms: 21 | - name: amznlnx-ec2 22 | driver: 23 | image_id: ami-60b6c60a 24 | transport: 25 | username: ec2-user 26 | - name: ubuntu-14.04-ec2 27 | driver: 28 | image_id: ami-7e055c14 29 | transport: 30 | username: ubuntu 31 | - name: ubuntu-14.04-local 32 | driver: 33 | name: vagrant 34 | box: opscode-ubuntu-14.04 35 | box_url: https://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/opscode_ubuntu-14.04_chef-provisionerless.box 36 | - name: centos-7.1-ec2 37 | driver: 38 | image_id: ami-61bbf104 39 | transport: 40 | username: centos 41 | - name: centos-7.1-local 42 | driver: 43 | name: vagrant 44 | box: opscode-centos-7.1 45 | box_url: http://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/opscode_centos-7.1_chef-provisionerless.box 46 | 47 | suites: 48 | - name: default 49 | run_list: 50 | - recipe[jenkins-config::default] 51 | attributes: 52 | -------------------------------------------------------------------------------- /Berksfile: -------------------------------------------------------------------------------- 1 | source 'https://supermarket.chef.io' 2 | 3 | cookbook 'java' 4 | cookbook 'git' 5 | cookbook 'magic_shell' 6 | cookbook 'jenkins' 7 | cookbook 'jenkins-config', :path => './cookbooks/jenkins-config/' 8 | 9 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | gem 'berkshelf' 3 | gem 'test-kitchen' 4 | gem 'kitchen-vagrant' 5 | gem 'kitchen-ec2' 6 | gem 'serverspec-extended-types', '~> 0.0.3' 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # tophat :tophat: 2 | 3 | I'm so over setting up Jenkins servers. This repo contains everything you need to create a Jenkins AMI using Packer. Then you just start using that AMI. So easy. 4 | 5 | You already have [Berkshelf](http://berkshelf.com/) and [Packer](https://www.packer.io/intro/getting-started/setup.html) installed, right? Nice. 6 | 7 | Make sure you have the [AWS CLI](https://aws.amazon.com/cli/) installed and configured. 8 | 9 | You'll also need to have a subnet and security group in which instances will be launched. 10 | 11 | Run to build a new Jenkins AMI: 12 | 13 | ./packer-build.sh sg-XXXXXXXX subnet-YYYYYYYY 14 | 15 | And then go do some real work. 16 | 17 | ### Developing 18 | 19 | If you're going to develop this cookbook, install [Test Kitchen](http://kitchen.ci/), and set the following 20 | environment variables: 21 | 22 | export TOPHAT_SG=sg-XXXXXXXX 23 | export TOPHAT_SUBNET_ID=subnet-YYYYYYYY 24 | export TOPHAT_EC2_KEY=my_ec2_key_name 25 | 26 | `.kitchen.yml` looks for those variables when provisioning a new instance. 27 | -------------------------------------------------------------------------------- /chefignore: -------------------------------------------------------------------------------- 1 | .kitchen 2 | -------------------------------------------------------------------------------- /circle.yml: -------------------------------------------------------------------------------- 1 | general: 2 | branches: 3 | only: 4 | - feature/circleci 5 | 6 | deployment: 7 | aws: 8 | commands: 9 | - ./packer-build.sh 10 | 11 | machine: 12 | ruby: 13 | version: '2.2.1' -------------------------------------------------------------------------------- /cookbooks/jenkins-config/attributes/default.rb: -------------------------------------------------------------------------------- 1 | if ['rhel'].include?(node['platform_family']) 2 | # default repository should be the Long-Term Support release 3 | # https://wiki.jenkins-ci.org/display/JENKINS/LTS+Release+Line 4 | node.default['jenkins']['master']['repository'] = 'http://pkg.jenkins-ci.org/redhat-stable' 5 | node.default['jenkins']['master']['repository_key'] = 'http://pkg.jenkins-ci.org/redhat-stable/jenkins-ci.org.key' 6 | end 7 | if ['debian'].include?(node['platform_family']) 8 | node.default['apt']['compile_time_update'] = true 9 | # default repository should be the Long-Term Support release 10 | # https://wiki.jenkins-ci.org/display/JENKINS/LTS+Release+Line 11 | node.default['jenkins']['master']['repository'] = 'http://pkg.jenkins-ci.org/debian-stable' 12 | node.default['jenkins']['master']['repository_key'] = 'http://pkg.jenkins-ci.org/debian-stable/jenkins-ci.org.key' 13 | end 14 | -------------------------------------------------------------------------------- /cookbooks/jenkins-config/attributes/java.rb: -------------------------------------------------------------------------------- 1 | # default to jdk version 7, new standard 2 | # for Jenkins 3 | node.default['java']['jdk_version'] = '7' 4 | -------------------------------------------------------------------------------- /cookbooks/jenkins-config/attributes/jenkins-plugins.rb: -------------------------------------------------------------------------------- 1 | node.default['jenkins-config']['jenkins-plugins'] = [ 2 | {'name' => 'git', 3 | 'version' => '2.4.1'}, 4 | {'name' => 'job-dsl'}, 5 | {'name' => 'envinject'}, 6 | {'name' => 'rvm'}, 7 | {'name' => 'token-macro'}, 8 | {'name' => 'ruby-runtime'}, 9 | {'name' => 'ansicolor'}, 10 | {'name' => 'delivery-pipeline-plugin'}, 11 | {'name' => 'aws-codepipeline'}, 12 | {'name' => 'workflow-aggregator'} 13 | ] 14 | 15 | -------------------------------------------------------------------------------- /cookbooks/jenkins-config/attributes/prereqs.rb: -------------------------------------------------------------------------------- 1 | if ['rhel'].include?(node['platform_family']) 2 | node.default['jenkins-config']['prereq']['packages'] = %w{patch libyaml-devel glibc-headers autoconf gcc-c++ glibc-devel readline-devel zlib-devel libffi-devel openssl-devel automake libtool bison sqlite-devel python-pip git mlocate} 3 | elsif ['debian'].include?(node['platform_family']) 4 | node.default['jenkins-config']['prereq']['packages'] = %w{patch libyaml-dev libc6-dev autoconf gcc libreadline-dev zlib1g-dev libffi-dev openssl automake libtool bison libsqlite3-dev python-pip git mlocate} 5 | end 6 | 7 | 8 | -------------------------------------------------------------------------------- /cookbooks/jenkins-config/files/default/etc-profile-d-homebin.sh: -------------------------------------------------------------------------------- 1 | PATH=$PATH:$HOME/bin 2 | export PATH 3 | -------------------------------------------------------------------------------- /cookbooks/jenkins-config/metadata.rb: -------------------------------------------------------------------------------- 1 | name 'jenkins-config' 2 | depends 'java' 3 | depends 'git' 4 | depends 'jenkins' 5 | 6 | version '0.0.0' 7 | -------------------------------------------------------------------------------- /cookbooks/jenkins-config/recipes/default.rb: -------------------------------------------------------------------------------- 1 | # Cookbook name:: jenkins-config 2 | # Recipe:: default 3 | # 4 | # Configure a Jenkins master 5 | 6 | include_recipe 'jenkins-config::prereqs' 7 | include_recipe 'java' 8 | include_recipe 'git' 9 | include_recipe 'jenkins::master' 10 | include_recipe 'jenkins-config::jenkins-plugins' 11 | # include_recipe 'jenkins-config::jenkins-jobs' 12 | include_recipe 'jenkins-config::homebin' 13 | include_recipe 'jenkins-config::jenkins-auth' 14 | -------------------------------------------------------------------------------- /cookbooks/jenkins-config/recipes/homebin.rb: -------------------------------------------------------------------------------- 1 | cookbook_file '/etc/profile.d/zz-home-bin.sh' do 2 | source 'etc-profile-d-homebin.sh' 3 | owner 'root' 4 | group 'root' 5 | mode '0644' 6 | action :create 7 | end 8 | -------------------------------------------------------------------------------- /cookbooks/jenkins-config/recipes/jenkins-auth.rb: -------------------------------------------------------------------------------- 1 | jenkins_script 'add_authentication' do 2 | command <<-EOH.gsub(/^ {4}/, '') 3 | import jenkins.model.* 4 | import hudson.security.* 5 | 6 | def instance = Jenkins.getInstance() 7 | 8 | def hudsonRealm = new HudsonPrivateSecurityRealm(false) 9 | 10 | def userdetails = null 11 | try { 12 | userdetails = hudsonRealm.loadUserByUsername("stelligent") 13 | } catch (e) { 14 | assert e in org.acegisecurity.userdetails.UsernameNotFoundException 15 | } 16 | 17 | if (userdetails == null) { 18 | hudsonRealm.createAccount("stelligent","Automation4thePPL") 19 | instance.setSecurityRealm(hudsonRealm) 20 | 21 | def strategy = new GlobalMatrixAuthorizationStrategy() 22 | strategy.add(Jenkins.ADMINISTER, "stelligent") 23 | strategy.add(Jenkins.READ, "anonymous") 24 | instance.setAuthorizationStrategy(strategy) 25 | instance.save() 26 | } 27 | EOH 28 | end 29 | -------------------------------------------------------------------------------- /cookbooks/jenkins-config/recipes/jenkins-jobs.rb: -------------------------------------------------------------------------------- 1 | template "/var/tmp/job-seed.xml" do 2 | source 'job-seed.xml.erb' 3 | 4 | variables( 5 | { 6 | :source_repo => node[:project][:git][:repo] 7 | } 8 | ) 9 | end 10 | 11 | jenkins_job "job-seed" do 12 | action :create 13 | config "/var/tmp/job-seed.xml" 14 | end 15 | -------------------------------------------------------------------------------- /cookbooks/jenkins-config/recipes/jenkins-plugins.rb: -------------------------------------------------------------------------------- 1 | # node['jenkins-config']['jenkins-plugins'] should be an array 2 | # of hashes like 3 | # 4 | # node['jenkins-config']['plugins'] = [ 5 | # { 'name' => 'git', 6 | # 'version' => '2.4.0 }, 7 | # { 'name' => 'ssh-credentials', 8 | # 'version' => '1.11', 9 | # 'core' => true } ] 10 | # 11 | # name: required, name of plugin to install 12 | # version: optional, version of plugin 13 | # core: optional, whether to create a .pinned file for a core module 14 | # pinned: optional, alias to core 15 | 16 | node['jenkins-config']['jenkins-plugins'].each do |plugin| 17 | if plugin['core'] || plugin['pinned'] 18 | file "/var/lib/jenkins/plugins/#{plugin['name']}.jpi.pinned" do 19 | mode '0644' 20 | owner node['jenkins']['master']['user'] 21 | group node['jenkins']['master']['group'] 22 | action :touch 23 | end 24 | end 25 | jenkins_plugin plugin['name'] do 26 | version plugin['version'] unless plugin['version'].nil? 27 | end 28 | end unless node['jenkins-config']['jenkins-plugins'].nil? || 29 | !node['jenkins-config']['jenkins-plugins'].respond_to?(:each) 30 | 31 | log 'restarting jenkins after plugin installs' do 32 | notifies :restart, 'service[jenkins]', :immediately 33 | end 34 | 35 | -------------------------------------------------------------------------------- /cookbooks/jenkins-config/recipes/master.rb: -------------------------------------------------------------------------------- 1 | include_recipe 'jenkins-config::default' 2 | include_recipe 'jenkins::master' 3 | include_recipe 'jenkins-config::jenkins-plugins' 4 | # include_recipe 'jenkins-config::jenkins-jobs' 5 | include_recipe 'jenkins-config::homebin' 6 | 7 | service 'jenkins' do 8 | action :restart 9 | end 10 | -------------------------------------------------------------------------------- /cookbooks/jenkins-config/recipes/prereqs.rb: -------------------------------------------------------------------------------- 1 | packages = node.default['jenkins-config']['prereqs']['packages'] 2 | packages.each do |package| 3 | package package 4 | end 5 | -------------------------------------------------------------------------------- /cookbooks/jenkins-config/recipes/slave.rb: -------------------------------------------------------------------------------- 1 | include_recipe 'jenkins-config::default' 2 | include_recipe 'jenkins-config::prereqs' 3 | 4 | -------------------------------------------------------------------------------- /cookbooks/jenkins-config/recipes/update-plugins.rb: -------------------------------------------------------------------------------- 1 | # Cookbook Name:: jenkins-config 2 | # Recipe:: update-plugins 3 | # 4 | # Update installed plugins to latest version 5 | 6 | # XXX this code is broken on Ubuntu 7 | # (curl not installed by default) 8 | # 9 | # Is this the best way? 10 | 11 | bash 'update jenkins plugins' do 12 | flags '-ex' 13 | code <<-EOB 14 | wait_for_jenkins() { 15 | count=0 16 | jenkins_running='false'; 17 | while [ "$jenkins_running" = 'false' ]; do 18 | test $count -lt 30 || exit 1 19 | if curl -s -o ~/jenkins-cli.jar http://127.0.0.1:8080/jnlpJars/jenkins-cli.jar && \ 20 | file ~/jenkins-cli.jar | grep -q 'Zip archive'; then 21 | jenkins_running='true' 22 | else 23 | sleep 3 24 | fi 25 | count=$(($count + 1)) 26 | done 27 | } 28 | 29 | wait_for_jenkins 30 | 31 | [ -e ~/jenkins-cli.jar ] || \ 32 | curl -s -o ~/jenkins-cli.jar http://127.0.0.1:8080/jnlpJars/jenkins-cli.jar 33 | 34 | UPDATE_LIST=$(java -jar ~/jenkins-cli.jar -s http://127.0.0.1:8080/ list-plugins | grep ')$' | awk '{ print $1 }') 35 | [ -n "${UPDATE_LIST}" ] || exit 0 36 | 37 | echo Updating Jenkins Plugins: ${UPDATE_LIST}; 38 | java -jar ~/jenkins-cli.jar -s http://127.0.0.1:8080/ install-plugin ${UPDATE_LIST} 39 | 40 | java -jar ~/jenkins-cli.jar -s http://127.0.0.1:8080/ safe-restart 41 | sleep 10 42 | wait_for_jenkins 43 | EOB 44 | end 45 | 46 | -------------------------------------------------------------------------------- /cookbooks/jenkins-config/templates/job-seed.xml.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Runs the Job DSL generator to create the pipeline. Also sets up the initial gemset, and runs a Cucumber test to ensure that the jobs were correctly created. 5 | false 6 | 7 | 8 | 2 9 | 10 | 11 | <%= @source_repo %> 12 | 13 | 14 | 15 | 16 | */master 17 | 18 | 19 | false 20 | 21 | 22 | 23 | true 24 | false 25 | false 26 | false 27 | 28 | false 29 | 30 | 31 | gem install bundler 32 | bundle install 33 | 34 | 35 | pipeline/jobs/jobdsl.groovy 36 | false 37 | false 38 | IGNORE 39 | IGNORE 40 | JENKINS_ROOT 41 | 42 | 43 | 44 | # run some tests for your jobs here 45 | 46 | 47 | 48 | 49 | 50 | xterm 51 | 52 | 53 | 54 | 55 | 2.2.2 56 | 57 | rvm 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /jenkins.json: -------------------------------------------------------------------------------- 1 | { 2 | "variables": { 3 | "vpc_id": "", 4 | "subnet_id": "", 5 | "sg_id": "", 6 | "berks_cookbooks_path": "", 7 | "git_repo": "" 8 | }, 9 | "builders": [ 10 | { 11 | "type": "amazon-ebs", 12 | "associate_public_ip_address": true, 13 | "region": "us-east-1", 14 | "source_ami": "ami-60b6c60a", 15 | "instance_type": "m4.large", 16 | "ssh_username": "ec2-user", 17 | "ssh_pty" : "true", 18 | "ami_name": "tophat-{{isotime \"2006-01-02-1504\"}}", 19 | "subnet_id": "{{user `subnet_id`}}", 20 | "vpc_id": "{{user `vpc_id`}}", 21 | "security_group_id": "{{user `sg_id`}}" 22 | } 23 | ], 24 | "provisioners": [ 25 | { 26 | "type": "chef-solo", 27 | "cookbook_paths": [ 28 | "{{user `berks_cookbooks_path`}}" 29 | ], 30 | "run_list": [ 31 | "jenkins-config::default" 32 | ], 33 | "json": { 34 | "java": { 35 | "jdk_version": "7" 36 | }, 37 | "project": { 38 | "git": { 39 | "repo": "{{user `git_repo`}}" 40 | } 41 | }, 42 | "jenkins": { 43 | "executor": { 44 | "timeout": 60 45 | } 46 | } 47 | } 48 | },{ 49 | "type": "file", 50 | "source": "./test/", 51 | "destination": "/tmp/infra-tests" 52 | },{ 53 | "type": "shell", 54 | "inline": [ 55 | "sudo yum -y install rubygem20-io-console", 56 | "sudo gem install serverspec", 57 | "sudo gem install bundler", 58 | "sudo sh -c 'cd /tmp/infra-tests/default/serverspec && /usr/local/bin/bundle install'", 59 | "sudo sh -c 'cd /tmp/infra-tests/default/serverspec && env RUBYLIB=`pwd` /usr/local/bin/rspec *_spec.rb'", 60 | "sudo rm -f $HOME/.ssh/authorized_keys /root/.ssh/authorized_keys" 61 | ] 62 | } 63 | ] 64 | } 65 | -------------------------------------------------------------------------------- /packer-build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -ex 3 | 4 | cd "$(dirname "$0")" 5 | berks_cookbook_path="./.berkscache" 6 | 7 | for arg in "$@"; do 8 | if [[ "$arg" = sg-* ]]; then 9 | TOPHAT_SG="$arg" 10 | elif [[ "$arg" = subnet-* ]]; then 11 | TOPHAT_SUBNET_ID="$arg" 12 | fi 13 | done 14 | 15 | subnet_id="$TOPHAT_SUBNET_ID" 16 | sg_id="$TOPHAT_SG" 17 | vpc_id="$(aws ec2 describe-subnets --subnet-ids $subnet_id --query 'Subnets[0].VpcId' --output=text)" 18 | 19 | test -n "$vpc_id" 20 | test -n "$subnet_id" 21 | test -n "$sg_id" 22 | 23 | [ -d "$berks_cookbook_path" ] || mkdir "$berks_cookbook_path" 24 | 25 | berks vendor "$berks_cookbook_path" 26 | packer build \ 27 | -var "vpc_id=$vpc_id" \ 28 | -var "subnet_id=$subnet_id" \ 29 | -var "sg_id=$sg_id" \ 30 | -var "berks_cookbooks_path=$berks_cookbook_path" \ 31 | jenkins.json 32 | -------------------------------------------------------------------------------- /test/integration/default/serverspec/Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | gem 'faraday' 4 | -------------------------------------------------------------------------------- /test/integration/default/serverspec/http_type.rb: -------------------------------------------------------------------------------- 1 | require 'faraday' 2 | require 'timeout' 3 | 4 | module Serverspec 5 | module Type 6 | class Http_Get < Base 7 | def initialize(url, timeout_sec=10) 8 | @url = url 9 | begin 10 | Timeout::timeout(timeout_sec) do 11 | getpage 12 | end 13 | rescue Timeout::Error 14 | @timed_out_status = true 15 | end 16 | end 17 | def getpage 18 | conn = Faraday.new 19 | response = conn.get(@url) 20 | @response_code_int = response.status 21 | @content_str = response.body 22 | @headers_hash = response.headers.dup 23 | end 24 | def timed_out? 25 | @timed_out_status 26 | end 27 | def headers 28 | @headers_hash 29 | end 30 | def status 31 | @timed_out_status ? 0 : @response_code_int 32 | end 33 | def body 34 | @content_str 35 | end 36 | 37 | private :getpage 38 | end 39 | def http_get(url, timeout_sec=10) 40 | Http_Get.new(url, timeout_sec) 41 | end 42 | end 43 | end 44 | 45 | include Serverspec::Type 46 | -------------------------------------------------------------------------------- /test/integration/default/serverspec/jenkins_plugins_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | # RedHat has curl 4 | describe command('curl -s -o ~/jenkins-cli.jar http://127.0.0.1:8080/jnlpJars/jenkins-cli.jar'), 5 | :if => %w(redhat amazon).include?(os[:family]) do 6 | its(:exit_status) { should eq 0 } 7 | end 8 | 9 | # Ubuntu has wget 10 | describe command('wget -q -O ~/jenkins-cli.jar http://127.0.0.1:8080/jnlpJars/jenkins-cli.jar'), 11 | :if => os[:family] == 'ubuntu' do 12 | its(:exit_status) { should eq 0 } 13 | end 14 | 15 | # verify all plugins defined in the plugins list 16 | # are output by the jenkins cli utility as installed 17 | # TODO 18 | # version checking 19 | describe command('java -jar ~/jenkins-cli.jar -s http://127.0.0.1:8080/ list-plugins') do 20 | its(:exit_status) { should eq 0 } 21 | plugins = %w(git job-dsl envinject rvm token-macro 22 | ruby-runtime ansicolor delivery-pipeline-plugin 23 | aws-codepipeline) 24 | plugins.each do |plugin| 25 | its(:stdout) { should match /#{plugin}/ } 26 | end 27 | end 28 | -------------------------------------------------------------------------------- /test/integration/default/serverspec/jenkins_service_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe package('jenkins'), :if => os[:family] == 'redhat' do 4 | it { should be_installed } 5 | end 6 | 7 | describe package('jenkins'), :if => os[:family] == 'ubuntu' do 8 | it { should be_installed } 9 | end 10 | 11 | describe service('jenkins'), :if => os[:family] == 'redhat' do 12 | it { should be_enabled } 13 | it { should be_running } 14 | end 15 | 16 | describe service('jenkins'), :if => os[:family] == 'ubuntu' do 17 | it { should be_enabled } 18 | it { should be_running } 19 | end 20 | 21 | describe port(8080), :if => 22 | %w(ubuntu redhat).include?(os[:family]) do 23 | it { should be_listening.with('tcp6') } 24 | end 25 | 26 | describe port(8080), :if => 27 | %w(amazon).include?(os[:family]) do 28 | it { should be_listening.with('tcp') } 29 | end 30 | 31 | describe http_get('http://localhost:8080/') do 32 | its(:body) { should match /Log in<\/a> to create new jobs/ } 33 | end 34 | -------------------------------------------------------------------------------- /test/integration/default/serverspec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | require 'serverspec' 2 | require 'http_type' 3 | 4 | set :backend, :exec 5 | 6 | --------------------------------------------------------------------------------