Unlimited Plugins, WordPress themes, videos & courses! Unlimited asset downloads! From $16.50/m
  1. Code
  2. Testing

Introduction to Jenkins: An Open Source Continuous Integration Server

This post is part of a series called Jenkins: An Open Source Continuous Integration Server.
Jenkins Workflow: Scripting Out Complex Builds
Sponsored Content

This sponsored post features a product relevant to our readers while meeting our editorial guidelines for being objective and educational.

Final product image
What You'll Be Creating

This is the first of a two-part series on Jenkins. Part two will be written by Ian Lollar because he has the best instructor profile image of any Tuts contributor. He also wrote the earlier Setting Up Continuous Integration & Continuous Deployment With Jenkins (Tuts+) which you may want to read as well. Just as a reminder, I do participate in the discussions below. If you have a question or topic suggestion, please post a comment below. You can also tweet me @reifmanemail me directly or tweet at Ian.

Jenkins is an extensible, open source continuous integration server. It builds and tests your software continuously and monitors the execution and status of remote jobs, making it easier for team members and users to regularly obtain the latest stable code.

In part one of this tutorial, I'll guide you through installing Jenkins and getting started. In part two, Ian will go more in depth, especially focusing on using the Jenkins Workflow Plugin. More information for this is available at the CloudBees documentation website.

Installing Jenkins

Create Your Droplet

I'm going to walk you through installing Jenkins on an Ubuntu 14.04 instance at Digital Ocean. Once you've registered or signed in to your Digital Ocean account, we'll need to create a new droplet for our Jenkins server.

Click the Create Droplet button to get started. I'm using jenkins.lookahead.io as my hostname. We can use the smallest droplet instance of $5/mo. and 512 MB.

Jenkins Digital Ocean Create Droplet

You can use whichever region is closest for you:

Jenkins Digital Ocean Create Droplet Select Region

Then, choose the Ubuntu 14.04 image and click Create Droplet:

Jenkins Digital Ocean Create Droplet Select Distribution

After a minute or so, you'll be redirected to your droplet configuration page with its IP address, e.g.

Jenkins Digital Ocean Droplet Created

You'll also receive an email with your login credentials:

Jenkins Digital Ocean Droplet Creation Email

Configure Your DNS Record

Then, go over to your domain registrar and configure a DNS A record for your hostname to point to the given IP address:

Jenkins DNS A Record Configuration

Accessing Your Server

To log in to your server, use the password in the Digital Ocean email. You'll need an SSH terminal program:

Then, create an admin user in the sudo group:

Log out and log back in with the admin user:

Installing Jenkins

To update Ubuntu with Jenkins source lists, type in the following commands:

To properly install Jenkins, I had success after updating my server and installing git beforehand:

I also had to reboot and initially manually start the Jenkins service. Your mileage may vary.

Then, visit your server using port 8080, e.g. http://jenkins.lookahead.io:8080, and you should see the Jenkins startup screen:

Welcome to Jenkins

Getting Started With Jenkins

Now, let's walk through the Jenkins user interface. On the left side of the page, you'll notice the navigation menus, e.g. New Item, People, Build History, Manage Jenkins and Credentials. There are also the Build Queue and Build Executor Status panes.

Managing Jenkins Credentials

Initially, Jenkins is completely insecure. Let's configure its Global Security from the Manage Jenkins sidebar menu option:

Jenkins Manage Jenkins

Click Configure Global Security:

Jenkins Configure Global Security

Then, from the home screen, sign up to create a new account and log back in:

Jenkins Sign up

Then, return to the Configure Global Security page and turn off the checkbox beside "Allow users to sign up":

This will prevent unauthorized visitors from creating new accounts.

The People Menu

You can manage the accounts on the system from the People menu in the left sidebar:

Jenkins People List

Click on the name of the user. This will load another level of left sidebar menu items specific to the selected person:

Jenkins People Menu and Detail page

Managing Plugins

Since we will likely want to integrate GitHub repositories into our build process at some point, here's how you can install the GitHub plugin.

Click the Manage Jenkins link, and then the Manage Plugins link. Switch to the Available tab, and search for the GitHub Plugin.

Jenkins Manage Plugins Available Tab

In my installation, I found I had to manually download the github.hpi plugin from the Jenkins code repository and then manually install the GitHub Plugin. 

Jenkins Repository GitHub plugin

From your Jenkins plugin manager, click the Advanced tab:

Jenkins Plugins Advanced

Scroll down to Upload Plugin and choose the github.hpi file:

Jenkins Upload Plugin

You should see a plugin installation screen like this:

Jenkins Plugin Installer Status

Creating Project Items and Sample Builds

Now, we'll create a sample project which integrates a simple GitHub repository pull and shell command. From the main Jenkins page, click New Item:

Jenkins New Item

Type in Shell Test and select Freestyle Project:

Jenkins Freestyle Project

After you click OK, you can configure the project further. For example's sake, I'm using Ian's Hello-Jenkins repository from Setting Up Continuous Integration & Continuous Deployment With Jenkins (Tuts+):

Jenkins Project Github Repository Pull

If you scroll down, you can also set build options and configure a sample shell command, e.g. uptime. Alternately, you could use this to run any build script you needed.

Jenkins Project Build Options and Shell Command

Once you save the options, you'll see the Jenkins project page, e.g. Project Shell Test. There's a menu on the left hand side for the project. If you click Build Now, Jenkins will schedule and build your project.

Jenkins Project Page

The Build History can be seen in the left hand pane. If you click on one of the build histories, you'll see the Jenkins build results:

Jenkins Project Build Page

Click Console Output to see the full results. You can see the git pull and the uptime shell command results:

Jenkins Project Build Console Output

Now you have a basic walkthrough of how Jenkins projects and builds work.

Other Jenkins Resources

If you'd like to follow along a more detailed video tutorial, check out Continuous Integration for PHP projects using Jenkins, Composer, PHPUnit, BitBucket and Digital Ocean:

You can also check out Ian's earlier Jenkins tutorial: Setting Up Continuous Integration & Continuous Deployment With Jenkins (Tuts+). The Jenkins website documentation and wiki is also quite thorough.

What's Next?

Next up, Ian will guide you through using the Jenkins Workflow Plugin. If part two isn't available yet, do check out Ian's earlier tutorial, Setting Up Continuous Integration & Continuous Deployment With Jenkins (Tuts+) and the CloudBees Workflow Plugin documentation website.

Please feel free to post your questions and comments below. You can also tweet me @reifmanemail me directly or tweet at Ian. You can also browse our Tuts+ instructor pages for other tutorials by me, Jeff Reifman, and Ian Lollar.

Related Links

Looking for something to help kick start your next project?
Envato Market has a range of items for sale to help get you started.