This article covers a version of Ubuntu that is no longer supported. If you are currently operate a server running Ubuntu 12.04, we highly recommend upgrading or migrating to a supported version of Ubuntu:
Reason: Ubuntu 12.04 reached end of life (EOL) on April 28, 2017 and no longer receives security patches or updates. This guide is no longer maintained.
This guide might still be useful as a reference, but may not work on other Ubuntu releases. If available, we strongly recommend using a guide written for the version of Ubuntu you are using. You can use the search functionality at the top of the page to find a more recent version.
Jenkins is an open source Continuous Integration tool. Originally started as Hudson in 2004 but due to a dispute in 2011 they forked and continued under the name, Jenkins. It can be used to build software, deploy software, or websites to various endpoints or to run unit/behaviour-driven software tests. This article will demonstrate how to install, configure Jenkins, and create your first job. After setting up the basics, you'll schedule the build on specific times and install a plugin.
Before we can install Jenkins, we have to add the key and source list to apt. This is done in 2 steps, first we'll add the key.
wget -q -O - http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key | apt-key add -
Secondly, we'll create a sources list for Jenkins.
echo deb http://pkg.jenkins-ci.org/debian binary/ > /etc/apt/sources.list.d/jenkins.list
Now, we only have to update apt's cache before we can install Jenkins.
As the cache has been updated we can proceed installing Jenkins. Note that Jenkins has a big bunch of dependencies, so it might take a few moments to install them all.
apt-get install jenkins
Now that Jenkins is running, go to ci.company.net:8080. You'll be welcomed by the default Jenkins screen.
Currently, the installation is insecure and everyone can access it. Lets fix that! First, go to Manage Jenkins (in the left menu) then click Setup Security on the page loaded:
Then enable the security by checking:
Set it to use Jenkins's own user database and disable sign ups:
Next, go for the Matrix-based security:
Make sure Anonymous only has the Read right under the View group (Jenkins crashes when it doesn't have that set):
Click save at the bottom of the page. After the page load, you'll see a login form, ignore that, go to ci.company.net:8080 again instead. You'll see this sign up form:
Sign up with the username hudson (or any other name to your liking, since Jenkins is assuming a lower case username I strongly suggest you choose as such to avoid confusion) and you'll be administrator of this fresh Jenkins install.
Now that everything is up and running, it's time to create our first job. Click the New Job link:
Create a freestyle project named uptime:
Press Ok and on the next page, add a Execute shell build step:
For the Command field, fill in uptime:
Click the save button at the bottom of the screen. Once the next page is finished, loading click the Build Now button.
Very shortly after click, you'll see the build show up in the build history block:
Click the blue sphere for the console output:
Jenkins can run your job on-demand or at a specific time. Now that we've set up the basic build, it's time to configure a build schedule. First, click the back to project link to return to the job overview:
Once you're back on the overview, click the Configure button:
This leads you to the configuration page as shown when you first set up the job. Now look for Build Triggers and check Build periodically:
Now this input field accepts the Crontab syntax, so setting it to @hourly runs it every hour and * * * * * runs it every minute. If you want to do old school nightly builds like Firefox or WebKit, set it to @midnight to start it between midnight and 2:59 AM. We'll set it to 0 */6 * * *, starting it every 6 hours providing you a fresh build 4 times per day. When the job is saved, the scheduler will start the job at its designated times.
There are a few special extras that come with Jenkins's scheduler. Check the blue question mark at the right of the input field to find out what exactly.
There is a vast amount of plugins available for Jenkins. Ranging from build tools to FTP and SSH publishers to test coverage reports to Chuck Norris. We're going to install a plugin that keeps track of the disk space used by different builds and jobs. This makes it easier to look for space eaters. To get started, go to Manage Jenkins again. And click on Manage Plugins:
Look for the Disk Usage Plugin and select it:
Once your done, click on the Install without the restart button at the bottom of your screen:
Just wait until the plugin has been installed and it's ready for use.
While this is a fairly simple plugin with no settings, there are plugins, such as the SSH plugin, that require some configuration after installing before you can use them properly.
Congratulations, you have just created and built your first job! Scheduled it to run every six hours providing around the clock builds. You also installed a plugin to keep track of all your jobs disk usage. While the job is completely useless and only displays the uptime and current load, it does show Jenkins's power available when crafting jobs. Especially combined with plugins, Jenkins is an incredible powerful tool.
If you’ve enjoyed this tutorial and our broader community, consider checking out our DigitalOcean products which can also help you achieve your development goals.