Installing Jenkins on Ubuntu

Published on: Thu, Apr 30, 2015 at 1:30 pm EST
Server Apps Ubuntu

Jenkins is a CI (continuous integration) server. It can be a very handy tool for developers. In this tutorial, I will show you how to install and setup Jenkins.

Step 1: Installing Jenkins

First off, we need to add the key and source list to apt. We can do this by executing the following commands.

wget -q -O - http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key | apt-key add -
echo deb http://pkg.jenkins-ci.org/debian binary/ > /etc/apt/sources.list.d/jenkins.list
apt-get update

Next, install Jenkins. Note that this can take quite some time.

apt-get install jenkins

Step 2: Accessing Jenkins

Time to configure Jenkins. By default, Jenkins runs on port 8080, so you can access it by visiting http://[SERVER_IP]:8080 in your web browser.

By default, everyone has access to Jenkins. You may want to add a password so that not everyone can use it. To add a password, go to "Manage Jenkins" (left). You will see a warning; click on "Setup Security" next to it.

When asked, choose "Jenkins's own user database" and "Matrix-based security". Anonymous should only have "Read". Save these settings.

Jenkins will ask you to sign up now. Choose a username, password, email address, and full name. Click "Sign up". You'll now be the administrator of your Jenkins server.

Step 3: Using Jenkins on port 80

If you want to be able to use a domain name with your Jenkins server, but you don't want people to have to type ":8080" after it each time, we can set up iptables so all traffic from port 80 will be redirected to port 8080. Add the following iptables rules.

iptables -A INPUT -i eth0 -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -i eth0 -p tcp --dport 8080 -j ACCEPT
iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 8080

Make sure to save and restart iptables.

service iptables save
service iptables restart

Step 3: Adding a job

In Jenkins, you can have multiple jobs; that basically means that you have multiple projects that you can build. To add a job, click "New Job" (you have to be logged in). From here, it should be pretty straight-forward; if you have a Maven project, click Maven of course!

Step 4: Using Apache and SSL for Jenkins

If you want to use Apache as a reverse proxy, that's easy with Jenkins!

You need the following Apache modules to be installed.

a2enmod proxy
a2enmod proxy_http

Now add a virtual host.

<VirtualHost *:443>
  ServerName jenkins.domain
  ServerAlias www.jenkins.domain

  SSLEngine On
  SSLCertificateFile    /etc/apache2/ssl/crt/jenkins.domain.crt
  SSLCertificateKeyFile /etc/apache2/ssl/key/jenkins.domain.key

  ProxyRequests     Off
  ProxyPass         /  http://localhost:8080/
  ProxyPassReverse  /  http://localhost:8080/
  ProxyPassReverse  /  http://jenkins.host/
  <Proxy http://localhost:8080/*>
    Order allow,deny
    Allow from all
  </Proxy>
  ProxyPreserveHost on
</VirtualHost>

This will allow you to use Jenkins with SSL.

Step 5: Installing plugins

There are a lot of plugins for Jenkins; they allow you to do a lot of things. To install a plugin, go to "Manage Jenkins" and then click on "Manage Plugins". This area will allow you to install plugins.

Step 6: Increase Maven's memory

Although this is slightly off-topic, I still thought I'd share how to increase the memory assigned to Maven. You need to edit MAVEN_OPTS. For example:

set MAVEN_OPTS="-Xmx1024m -XX:MaxPermSize=128m"

Written by William David Edwards

Want to contribute ?

You could earn up to $300 by adding new articles