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.
See Instead:
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.
apt-get update
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.
Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
A very good tutorial - step by step to success.
I didn’t get the assumption: It’s assumed that ci.company.net points to the box you’re installing Jenkins on. Where can I get more information?
@aramis001: You basically have to replace <strong>ci.company.net</strong> with the domain name that you are going to host Jenkins on.
Good work. I’d just recommend using the stable releases of Jenkins available at http://pkg.jenkins-ci.org/debian-stable/
Also, the article is written for Ubuntu 13.04, but the title still says 12.04.
Cheers.
@jcmuller Thanks! I’ve written and completely tested the article through on a 13.04 VPS but been using Jenkins on Ubuntu as early as 12.04 so I know it also works from there and up. Also thanks for the tip about the stable release. I’ll get in touch with Etel to include that in the article.
It would be cool to see this updated to include configuring Jenkins to be using SSL, such as running a nginx server in front of it with an SSL certificate for the site.
Just a heads up to would-be users of the smallest droplet for this tutorial: Jenkins is likely to fail with OutOfMemory errors with only 512MB allocated to your droplet. The symptom for this is if you’ve gotten past the
apt-get install jenkins
step but cannot reach the page via your browser, and you can see the error output by taking a look at the Jenkins log file at /var/log/jenkins/jenkins.log.I got around this by resizing up to a 2GB instance, but YMMV.
Great guide, but it doesn’t seem to work for me. Whenever I go to {my-ip}:8080, I get a timeout saying the host takes too long to respond.
@nickgobee0122: Can you check "/var/log/jenkins/jenkins.log " and post any relevant errors?
Sorry, my bad. I had a friend of mine set up my droplet, and he didn’t tell me about the firewall which was blocking port 8080.
So once that was open, it worked like a charm. Thanks for the quick response though :)
Stuck on step one:
wget -q -O - http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key | apt-key add -
I get this error:
ERROR: This command can only be used by root.
I created a 512mb droplet, and followed this tutorial to ‘set it up’: https://www.digitalocean.com/community/articles/initial-server-setup-with-ubuntu-14-04
@samt: If you are not the root user, you must prepend “sudo” to the command. So it would be:
<pre> sudo wget -q -O - http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key | apt-key add - </pre>
Yes, still get the same error. I think when setting up current user I must have given root privilidge wrong when following this tutorial: https://www.digitalocean.com/community/articles/initial-server-setup-with-ubuntu-14-04
@samt: Did you disable root login via SSH? If so, you’ll need to login via the web console. Run the command <code>visudo</code> and make sure the contents of the file look like:
<pre>
User privilege specification
root ALL=(ALL:ALL) ALL yourusername ALL=(ALL:ALL) ALL </pre>
Okay, so I’ve made it thorough to the end, but don’t see anything when I browse to http://[myip]:8080
The log is:
May 24, 2014 12:55:46 PM winstone.Logger logInternal INFO: Beginning extraction from war file Jenkins home directory: /var/lib/jenkins found at: EnvVars.masterEnvVars.ge$ May 24, 2014 12:55:53 PM winstone.Logger logInternal INFO: HTTP Listener started: port=8080 May 24, 2014 12:55:53 PM winstone.Logger logInternal INFO: Winstone Servlet Engine v0.9.10 running: controlPort=disabled May 24, 2014 12:55:54 PM jenkins.InitReactorRunner$1 onAttained INFO: Started initialization May 24, 2014 12:55:54 PM jenkins.InitReactorRunner$1 onAttained INFO: Listed all plugins May 24, 2014 12:55:54 PM jenkins.InitReactorRunner$1 onAttained INFO: Prepared all plugins May 24, 2014 12:55:54 PM jenkins.InitReactorRunner$1 onAttained INFO: Started all plugins May 24, 2014 12:55:54 PM jenkins.InitReactorRunner$1 onAttained INFO: Augmented all extensions May 24, 2014 12:55:58 PM jenkins.InitReactorRunner$1 onAttained INFO: Loaded all jobs May 24, 2014 12:55:59 PM jenkins.InitReactorRunner$1 onAttained INFO: Completed initialization May 24, 2014 12:55:59 PM hudson.TcpSlaveAgentListener <init> INFO: JNLP slave agent listener started on TCP port 46441 May 24, 2014 12:55:59 PM hudson.WebAppMain$2 run INFO: Jenkins is fully up and running
Any Ideas?
Okay, turned brain on and solved the problem. This article has a major dependency not listed (which is quite obvious, but still should prob be added): A web server like apache or nginx needs to be set up, plus proxys: https://wiki.jenkins-ci.org/display/JENKINS/Installing+Jenkins+on+Ubuntu
When I get to the “apt-get update” step I get an error saying “Reading package lists… Error!” Any ideas?
@adams.jonathan: Can you pastebin the full error? Thanks!
Hi everybody, thanks for this guide!!! But i have some problem when try to run some bash script with sudo. I tried in a different way…
This is my visudo:
User privilege specification
root ALL=(ALL:ALL) ALL dev ALL=NOPASSWD:ALL jenkins ALL=NOPASSWD:ALL
Where the user “dev” is the user that use to access to the jenkins slave, and the user “jerkins” i suppose that is the user that run the script.
And this is the jenkins log:
Can you help me?
@fontanelli.filippo: Try running
sudo visudo
and adding the following abovejenkins ALL=NOPASSWD:ALL
:I enabled Matrix-based security and my user got locked. Unable to login and do anthing.
How install Jenkins if I have a Apache Tomcat listening on port 8080? Download a .war and deploy into Tomcat webapp’s folder?
To modify the default port of Jenkins is very simple, do it by modifying /etc/default/jenkins.
Change the following setting:
Change the post number to any port you want rather than 80.
After saving you can manually start jenkins like this:
You should see the following:
Thanks a ton for the detailed article.
Good work DO. I love your articles. I have one question though. Should I use this tutorial or the one from Rosehosting for installing Jenkins on Ubuntu 14.04 I know that the commands are the same, but will this article work for Ubuntu 14.04 ?
Tons of thanks for your effort in providing me with a proper answer.
Hey Original author here, yes this article will work on Ubuntu 14.04. Running it myself on 14.04 as well :).
Good job. Very clear, even for newcomers to the Java/Jenkins world. Thanks.
The screenshot under “Set it to use Jenkins’s own user database and disable sign ups:” could have the radio box checked. I see no reason for the screenshot to show it empty. If it is empty and the directions are followed, Jenkins will be locked out. The illustration (the way it is now) for this instruction does more to detract from the goal than the help it.
This step says “After the page load, you’ll see a login form, ignore that, go to ci.company.net:8080 again instead.” I think “load” should be “loads”.
Hi everyone, i tried to install using this tutorial but doesn’t work to me. I’m acessing the browser with http://{my_ip}:8080 and have a ERR_CONNECTION_TIMED_OUT error. Sorry my bad english.
Do you have any firewall running and blocking those ports?
netstat -tulpen | grep 8080
shows you if something is listening on that specific port. If there is something listening on that port check your firewalls documentation otherwise check /var/log/jenkins/jenkins.log for possible clues.Informative tutorial. Only mention Java pre-requisites.
Ubuntu 14.04 needs
service jenkins start
after installingFor future reference: on Ubuntu 14.04 there’s another dependency: I had to update the default java version:
Had trouble getting this started. Looked at the date, 2013. Today is 2016. The load scripts at the beginning are different now.
wget -q -O - https://jenkins-ci.org/debian/jenkins-ci.org.key | sudo apt-key add -
sudo sh -c 'echo deb http://pkg.jenkins-ci.org/debian binary/ > /etc/apt/sources.list.d/jenkins.list'
sudo apt-get update
sudo apt-get install jenkins