If you use Vagrantfile below, your Jenkins server will be up and running in Ubuntu 14.04 environment. It will also be accessible via http://192.168.10.11:8080/ from the host OS.


Vagrantfile


# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/trusty64"

config.vm.define :jenkins do |jenkins_config|
jenkins_config.vm.hostname = 'jenkins'
jenkins_config.vm.network "private_network", ip: "192.168.10.11"
end

config.vm.provider :virtualbox do |virtualbox_config|
virtualbox_config.name = "Jenkins - Ubuntu 14.04"
end

config.vm.provision :shell, path: "bootstrap.sh"

config.vm.synced_folder "", "/var/www/html", nfs: true, mount_options: ["actimeo=2"]
end

Bootstrap.sh


#!/usr/bin/env bash

# BEGIN ########################################################################
echo -e "-- ------------------ --\n"
echo -e "-- BEGIN BOOTSTRAPING --\n"
echo -e "-- ------------------ --\n"

# VARIABLES ####################################################################
echo -e "-- Setting global variables\n"
APACHE_CONFIG=/etc/apache2/apache2.conf
VIRTUAL_HOST=localhost
DOCUMENT_ROOT=/var/www/html

# BOX ##########################################################################
echo -e "-- Updating packages list\n"
apt-get update -y -qq

# APACHE #######################################################################
echo -e "-- Installing Apache web server\n"
apt-get install -y apache2

echo -e "-- Adding ServerName to Apache config\n"
grep -q "ServerName ${VIRTUAL_HOST}" "${APACHE_CONFIG}" || echo "ServerName ${VIRTUAL_HOST}" >> "${APACHE_CONFIG}"

echo -e "-- Allowing Apache override to all\n"
sed -i "s/AllowOverride None/AllowOverride All/g" ${APACHE_CONFIG}

echo -e "-- Updating vhost file\n"
cat > /etc/apache2/sites-enabled/000-default.conf <<EOF
<VirtualHost *:80>
ServerName ${VIRTUAL_HOST}
DocumentRoot ${DOCUMENT_ROOT}

<Directory ${DOCUMENT_ROOT}>
Options Indexes FollowSymlinks
AllowOverride All
Order allow,deny
Allow from all
Require all granted
</Directory>

ErrorLog ${APACHE_LOG_DIR}/${VIRTUAL_HOST}-error.log
CustomLog ${APACHE_LOG_DIR}/${VIRTUAL_HOST}-access.log combined
</VirtualHost>
EOF

echo -e "-- Restarting Apache web server\n"
service apache2 restart

# JAVA #########################################################################
echo -e "-- Installing JAVA packages\n"
apt-get install -y openjdk-7-jre > /dev/null 2>&1
apt-get install -y openjdk-7-jdk > /dev/null 2>&1

# JENKINS #########################################################################
echo -e "-- Including Jenkins packages\n"
wget -q -O - https://pkg.jenkins.io/debian/jenkins-ci.org.key | apt-key add - > /dev/null 2>&1
sh -c "echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list"

echo -e "-- Updating packages list\n"
apt-get update -y -qq
echo -e "-- Installing Jenkins automation server\n"
apt-get install jenkins -y -qq

# END ##########################################################################
echo -e "-- ---------------- --"
echo -e "-- END BOOTSTRAPING --"
echo -e "-- ---------------- --"