Installing Jenkins on an Ubuntu Amazon EC2 instance

Note: This post was written over four years ago and may no longer work correctly. This post will remain published for posterity.

This tutorial assumes you have already created an Amazon EC2 instance and are able to ssh to it. In our case, we used the Quick Launch Wizard to spin up a 32-bit instance of Ubuntu Server Cloud Guest 11.10 (Oneiric Ocelot).

Once you have a running EC2 instance you’ll need to modify the instance’s security group to open up ports 22, 80 and 443.

The first thing I did was update the EC2 timezone to our local timezone:

$ sudo ln -sf /usr/share/zoneinfo/America/Los_Angeles /etc/localtime

Install any version control systems you might like to use:

$ sudo apt-get install git

Then pretty much just follow the installation instructions from the Jenkins Wiki. I’ve copied the actual steps here for posterity.

Installing Jenkins:

$ wget -q -O - http://pkg.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 aptitude update
 
# Note this will install the openjdk dependencies automatically!
$ sudo aptitude install jenkins

Setting up an Apache Proxy for port 80 -> 8080:

$ sudo aptitude install apache2
$ sudo a2enmod proxy
$ sudo a2enmod proxy_http
$ sudo a2enmod vhost_alias
$ sudo a2dissite default
$ touch /etc/apache2/sites-available/jenkins

Use your favorite editor to update /etc/apache2/sites-available/jenkins with the following virtual host configuration:

<VirtualHost *:80>
	ServerAdmin webmaster@localhost
	ServerName ci.company.com
	ServerAlias ci
	ProxyRequests Off
	<Proxy *>
		Order deny,allow
		Allow from all
	</Proxy>
	ProxyPreserveHost on
	ProxyPass / http://localhost:8080/
</VirtualHost>

Enable the new jenkins virtual host and restart apache:

$ sudo a2ensite jenkins
$ sudo apache2ctl restart

Jenkins should now be live and accessible from port 80! Now you can begin configuring Jenkins to your liking. I’ll follow-up with a post highlighting our Jenkins configuration. For now, here are the plugins we’ve chosen to install:

  • Green Balls
  • Post build task
  • Instant Messaging Plugin
  • IRC Plugin
  • Rake plugin
  • Git Plugin
  • Github Plugin
  • GitHub API Plugin
  • Github OAuth Plugin

7 thoughts on “Installing Jenkins on an Ubuntu Amazon EC2 instance

  1. Thanks a ton, your instructions worked perfectly. A+ for being thorough and precise :)

  2. I have the same configuration but without nginx. Jenkins is runing on port 8080.
    Can you imagine any reason why I shouldn’t run jenkins on port 8080 ?

    I’m having some troubles with ssh keys (stderr: Permission denied (publickey).)

    • The only reason to run Jenkins on port 80 vs 8080 is to avoid having to type that into your browser since web traffic runs on port 80 by default.

  3. I have successfully setup jenkins on my localhost.i just need to configure my jenkins so that it will automate my deployment directly to my AWS AMI machine thorugh GITHUB.

  4. This tutorial is outdated and no longer works. I am getting these messages from apache:

    When I run ‘sudo a2dissite default’:
    ERROR: Site default does not exist!

    When I run ‘sudo a2ensite jenkins’:
    ERROR: Site jenkins does not exist!

    When I run ‘ls -l /etc/apache2/sites-available/’:
    -rw-r–r– 1 root root 1332 Jan 7 2014 000-default.conf
    -rw-r–r– 1 root root 6437 Jan 7 2014 default-ssl.conf
    -rw-r–r– 1 root root 244 Nov 16 23:32 jenkins

Comments are closed.