If you can set up a project server once, you can set up Jenkins to deploy that project again and again as you develop, maintain, and expand it.

In this post we will set up a multi-stage deploy server and the Jenkins jobs we need for continuous delivery. By the end you will know how to set up a server and Jenkins jobs to automatically deploy successfully built branches into each environment.

In a previous post we set up a dedicated Jenkins Server and gave it access to our projects’ GitHub account with an SSH key.

We will use a PHP project as an example, but we’ll also talk about how these same steps can be used to deploy most web projects regardless of language, framework, or other considerations.

Tools

In order to follow along with this post, you will need the following:

This same process can be used with non-PHP projects, but our example assumes PHP. You can also use servers hosted anywhere, but we’re using DigitalOcean for our example as their great documentation is a nice resource if you get stuck.

This setup uses two servers. The Jenkins Server which was created previously, and the Deploy Server which we’re creating here.

Overview

Moving forward we will walk through these steps:

The Deploy Server: We will create a single server set up to serve Test, Staging, and Production branches independently. You may want to set up each release phase on its own server, or pre-production release phases on one server and production on another, but in this example we will assume we want all of the release phases on a single server. The Deploy Server’s jenkins User: We’ll create a user on our deploy server for our Jenkins Server to access via SSH and run our deploy commands. SSH Setup in Jenkins: We’ll install and configure a plugin on our Jenkins Server so it knows how to access our deploy server. Creating a Jenkins Deploy Job: We’ll walk through all the steps to configure a new Jenkins job to be triggered by a commit to our repo, build and test our branch on the Jenkins Server, package and transmit that build to our Deploy Server, and setup the new build there. Testing Your Build: Finally, we’ll talk about how to keep an eye on in-progress build jobs and where to find logs to investigate failed builds.

The Deploy Server

First, create a new DigitalOcean Ubuntu droplet and go through the initial installations necessary to make it a LEMP stack.