Installing Jenkins on localhost with Vagrant

Róbert Darida
4 min readFeb 24, 2019

--

Introduction

What is Vagrant?

“ Vagrant is a tool for building and managing virtual machine environments in a single workflow. With an easy-to-use workflow and focus on automation, Vagrant lowers development environment setup time, increases production parity, and makes the “works on my machine” excuse a relic of the past.” You can read more about Vagrant here.

I really like to work with Vagrant, because it allows me to install several versions of the same framework, runtime, etc. without messing up my development environment. Also it has a DigitalOcean plugin which makes easier to create and setup Droplets.

List of Vagrant commands

What is Jenkins?

“ Jenkins is a self-contained, open source automation server which can be used to automate all sorts of tasks related to building, testing, and delivering or deploying software.”

So I use it to build, test, and deploy my Angular, Electron, and Java applications.

Why do I use it locally on my machine?

Formerly I was running a Jenkins instance on the cheapest ($5) DigitalOcean Droplet. It worked well with Java projects, but turned out soon the 1 GB memory isn’t enough for building NodeJS projects. So I upgraded the Droplet step by step from 1 GB to 4 GB. Of course, the monthly cost of the Droplet also moved up to $20. Two months later I realised it isn’t economical for me. In fact, I used it alone and rarely but if I were in a team, I would have kept the Droplet. I decided to move all my projects to a locally hosted Jenkins instance.

Where to start?

We need to install the latest version both of Virtual Box and Vagrant into our machine. They can be installed with default settings, but for more information you can check these videos: installing Virtual Box, installing Vagrant.

Vagrantfile

The Vagrantfile contains the parameters of the virtual machine which should be created. Copy the following script into your Vagrantfile. The script will create a virtual machine which has 2 CPUs and 4 GB memory, and runs an Ubuntu Xenial 64 operating system.

jenkins.sh

The jenkins.sh bash file contains the installation commands of Java, and Jenkins. (The latest Jenkins requires at least Java 8 Runtime Environment.)

Vagrant up

Next step is to open a cmd/terminal and run this command:

vagrant up

As you can see in the previous GIF, Vagrant creates a Virtual Box machine as it was described in the Vagrantfile and runs the jenkins.sh bash script as part of the provisioning. After the end of this process you can open the localhost:8080 in your browser and start to configure Jenkins.

Configuring Jenkins

Unlock Jenkins

The jenkins.sh prints out the “initial admin password” at the end of the provisioning. You have just copy & paste that password on the following page and then click on the Continue button.

The Customize Jenkins page will appear. Choose the Install suggested plugins option.

The installation will take a while. This is the perfect time to drink some coffee.

After the installation of the plugins you will need to fill the Create First Admin User form.

On the Instance Configuration page just press the Save and Finish button.

Now Jenkins is ready! You can start using it.

You will be automatically redirected to the Welcome page.

That’s it. You have a running Jenkins. If you would like to turn it off you’ve just run this command:

vagrant halt

In the following article I will detail how can you create a DigitalOcean Droplet with Vagrant:

If you enjoyed this article, please give it a few claps for support.

Thanks for reading!

--

--

Róbert Darida
Róbert Darida

Written by Róbert Darida

Software Engineer, Game Developer

Responses (3)