├── .gitignore
├── .travis.yml
├── JenkinsConfig
├── config.xml
└── users
│ └── admin
│ └── config.xml
├── LICENSE
├── README.md
├── Vagrantfile
├── VirtualHost
└── jenkins
├── provision.sh
└── tests
└── test_jenkins.bats
/.gitignore:
--------------------------------------------------------------------------------
1 | .idea/
2 | .vagrant/
3 | *.log
4 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: bash
2 |
3 | notifications:
4 | slack: tehnografija:yGLRFooashh7wutsGmMQFxou
5 |
6 | jobs:
7 | include:
8 | - stage: install Bats
9 | script:
10 | - sudo apt-get update
11 | - sudo apt-get install -y bats
12 | - stage: run Bats tests
13 | script:
14 | - bats tests/
15 |
--------------------------------------------------------------------------------
/JenkinsConfig/config.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 2.132
5 | RUNNING
6 | 2
7 | NORMAL
8 | true
9 |
10 | true
11 |
12 |
13 | true
14 | false
15 |
16 | false
17 |
18 | ${JENKINS_HOME}/workspace/${ITEM_FULL_NAME}
19 | ${ITEM_ROOTDIR}/builds
20 |
21 |
22 |
23 |
24 | 0
25 |
26 |
27 |
28 | all
29 | false
30 | false
31 |
32 |
33 |
34 | all
35 | -1
36 |
37 |
38 | false
39 |
40 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/JenkinsConfig/users/admin/config.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | admin
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 | all
15 | false
16 | false
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 | true
26 |
27 |
28 | #jbcrypt:$2a$10$V1SgiaBVbsUhOtiT1cHiqu.8NjJhFMtpGthV1GNMh801VoG.ejl7.
29 |
30 |
31 |
32 | authenticated
33 |
34 | 1531834932839
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 Edin Cenanovic
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Vagrant Jenkins build [](https://travis-ci.org/edinc/vagrant-jenkins)
2 |
3 | Run latest Jenkins instance on Ubuntu 16.04 LTS using vagrant.
4 |
5 | ## Prerequisites
6 | * [VirtualBox](https://www.virtualbox.org/)
7 | * [Vagrant](https://www.vagrantup.com/)
8 |
9 | ## Installation
10 | Build the vagrant box
11 |
12 | ```
13 | vagrant up
14 | ```
15 |
16 | To access the Jenkins server
17 |
18 | ```
19 | http://localhost:8080
20 | ```
21 |
22 | or, add the following line to the hosts file
23 |
24 | ```
25 | 127.0.0.1 jenkins.local
26 | ```
27 |
28 | and then run the server with
29 |
30 | ```
31 | http://jenkins.local:8080
32 | ```
33 |
34 | ## First time accessing Jenkins
35 |
36 | Jenkins is set up with one user with
37 | ```
38 | username: admin
39 | password: admin
40 | ```
41 | usual caveat about changing the password once setup.
42 |
43 | ## Bats Tests
44 |
45 | This repository includes tests written using [Bats](https://github.com/sstephenson/bats). These tests check if Jenkins is installed, if the Jenkins service is running, and if Jenkins is accessible on port 8080.
46 |
47 | To run the tests, use the following command:
48 |
49 | ```
50 | bats tests/
51 | ```
52 |
--------------------------------------------------------------------------------
/Vagrantfile:
--------------------------------------------------------------------------------
1 | # -*- mode: ruby -*-
2 | # vi: set ft=ruby :
3 |
4 | Vagrant.configure("2") do |config|
5 | config.vm.box = "ubuntu/focal64"
6 | config.vm.network "forwarded_port", guest: 80, host: 8080
7 | config.vm.synced_folder ".", "/mnt/host_machine", create: true
8 | config.vm.provider :virtualbox do |vb|
9 | vb.name = "jenkins"
10 | vb.memory = "2048"
11 |
12 | end
13 | config.vm.provision "shell" do |s|
14 | s.path = "provision.sh"
15 | end
16 | end
17 |
--------------------------------------------------------------------------------
/VirtualHost/jenkins:
--------------------------------------------------------------------------------
1 | upstream app_server {
2 | server 127.0.0.1:8080 fail_timeout=0;
3 | }
4 |
5 | server {
6 | listen 80;
7 | listen [::]:80 default ipv6only=on;
8 | server_name jenkins.local;
9 |
10 | location / {
11 | proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
12 | proxy_set_header Host $http_host;
13 | proxy_redirect off;
14 |
15 | if (!-f $request_filename) {
16 | proxy_pass http://app_server;
17 | break;
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/provision.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | VAGRANT_HOST_DIR=/mnt/host_machine
4 |
5 | ########################
6 | # Jenkins & Java
7 | ########################
8 | echo "Installing Jenkins and Java"
9 | wget -q -O - http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key | sudo apt-key add -
10 | sudo sh -c 'echo deb http://pkg.jenkins-ci.org/debian binary/ > /etc/apt/sources.list.d/jenkins.list'
11 | sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys FCEF32E745F2C3D5 > /dev/null 2>&1
12 | sudo apt-get update > /dev/null 2>&1
13 | sudo apt-get -y install default-jdk jenkins > /dev/null 2>&1
14 | echo "Installing Jenkins default user and config"
15 | sudo cp $VAGRANT_HOST_DIR/JenkinsConfig/config.xml /var/lib/jenkins/
16 | sudo mkdir -p /var/lib/jenkins/users/admin
17 | sudo cp $VAGRANT_HOST_DIR/JenkinsConfig/users/admin/config.xml /var/lib/jenkins/users/admin/
18 | sudo chown -R jenkins:jenkins /var/lib/jenkins/users/
19 |
20 | ########################
21 | # Node & npm
22 | ########################
23 | echo "Installing Node & npm"
24 | curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
25 | sudo apt-get -y install nodejs
26 | sudo apt-get -y install npm
27 |
28 | ########################
29 | # Docker
30 | ########################
31 | echo "Installing Docker"
32 | curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
33 | sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
34 | sudo apt-get update
35 | sudo apt-get -y install docker-ce
36 | sudo systemctl enable docker
37 | sudo usermod -aG docker ${USER}
38 | sudo usermod -aG docker jenkins
39 | sudo usermod -aG docker ubuntu
40 |
41 | ########################
42 | # nginx
43 | ########################
44 | echo "Installing nginx"
45 | sudo apt-get -y install nginx > /dev/null 2>&1
46 | sudo service nginx start
47 |
48 | ########################
49 | # Configuring nginx
50 | ########################
51 | echo "Configuring nginx"
52 | cd /etc/nginx/sites-available
53 | sudo rm default ../sites-enabled/default
54 | sudo cp /mnt/host_machine/VirtualHost/jenkins /etc/nginx/sites-available/
55 | sudo ln -s /etc/nginx/sites-available/jenkins /etc/nginx/sites-enabled/
56 | sudo service nginx restart
57 | sudo service jenkins restart
58 | echo "Success"
59 |
60 | ########################
61 | # Bats
62 | ########################
63 | echo "Installing Bats"
64 | sudo apt-get -y install bats
65 |
--------------------------------------------------------------------------------
/tests/test_jenkins.bats:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bats
2 |
3 | @test "Jenkins is installed" {
4 | run dpkg -l jenkins
5 | [ "$status" -eq 0 ]
6 | }
7 |
8 | @test "Jenkins service is running" {
9 | run systemctl is-active jenkins
10 | [ "$status" -eq 0 ]
11 | [ "$output" = "active" ]
12 | }
13 |
14 | @test "Jenkins is accessible on port 8080" {
15 | run curl -s -o /dev/null -w "%{http_code}" http://localhost:8080
16 | [ "$status" -eq 0 ]
17 | [ "$output" -eq 200 ]
18 | }
19 |
--------------------------------------------------------------------------------