Deploying a Jenkins Server to AWS Elastic Beanstalk

Helix
3 min readAug 19, 2018

--

In this step-by-step tutorial I will show you how to deploy Jenkins to AWS Elastic Beanstalk. There are many ways to do so, but the way i’m going to show you is probably the easiest. In a different post I will show you how to use Terraform to deploy the AWS Infrastructure. In this post I will only use the commandline.

Create a project directory

We will need a project directory which will contain the following at the end of the tutorial:

.ebextensions
.elasticbeanstalk
Procfile
jenkins.jar
jenkins.zip

Get the latest Jenkins

The first step is to get the latest Jenkins in your project folder. You can download it from the Jenkins website, https://jenkins.io, or use wget .

wget http://mirrors.jenkins-ci.org/war/latest/jenkins.war

The jenkins.war is actually a jar packaged Java application with an embedded Jetty server. The EB environment we will create will be a Java platform so we will need a jar file. Simply create the jar like this:

mv jenkins.war jenkins.jar

Create EB configuration files

Jenkins is mostly used with Git based projects. So we will need the EB environment to be able to use Git. Create a folder called .ebextensions and create in that folder a file called jenkins.config . Put the following in the file:

packages: 
yum:
git: []

Watch the indent! It should be 2 spaces. The format of the file is YAML. The .ebextensions folder is a way to configure your EB environment. The jenkins.config file contains a configuration option for the instance in the EB environment. In our case we need yum to install the latestgit for us. More on the use of .ebextensions can be found here:

The Java Platform EB environment runs with a proxy. The default is Apache, but there are more to choose from. We will stick with the default. Apache will listen on port 80 and route all traffic to the instance using port 5000.

Jenkins runs default on port 8080, so we will need to change it to port 5000. The easiest way to accomplish that is to start Jenkins like this:

java -jar jenkins.jar --httpPort=5000

There are a lot of useful commandline parameters to configure Jenkins. You can find them here:

Now we need a Procfile to tell the EB environment to start the jenkins.jar with commandline parameters. Create a Procfile with the following contents:

web: java -jar jenkins.jar --httpPort=5000

This tells the EB environment to start the main web application using this command. You can find more on the Procfile here:

Create a ZIP package

We need to bundle everything together in a jenkins.zip file to upload to the EB environment:

zip -r -X jenkins.zip jenkins.jar .ebextensions Procfile

Create the EB environment

This step requires you to have the Elastic Beanstalk CLI.

Make sure you are in your project folder. Use it as a working directory to create an EB application with the following command:

eb init

Be sure to select Java as a platform with version Java 8 .

This will result in a .elasticbeanstalk directory containing the file config.yml . In this file add an entry:

deploy: 
artifact: jenkins.zip

Now you can create an environment with:

eb create 

After 5 minutes your Jenkins will be live. Use the following command to get the URL to visit your Jenkins.

eb status

You can see the URL at the CNAME entry.

I hope this was helpful for people struggeling to get Jenkins running in an Elastic Beanstalk environment. It took me quite some time to figure out what is needed to get this simple setup up and running.

--

--

Helix

Trying to create IT solutions that are as simple as possible. It gets easier each day!