Create Jenkins Jobs using Capistrano 3 for NodeJS

Final component of the Continuous Integration and Deployment process using Capistrano and Jenkins, is …Jenkins. Jenkins is an open source Continuous Integration services tool, that allows users to define a set of tasks to be run either manually, or triggered by 3rd party applications.

This page presents how to integrate Jenkins and Capistrano 3; in order to trigger Capistrano recipes defined here. The assumptions are that Capistrano and Jenkins are installed on the same server, and recipes are stored in a  git repository outside the application repository.

Prepare Jenkins for Git based deployment

Prior to creating jobs, a few settings must be applied to Jenkins, for cloning a Git repository.

Step 1: Open the Plugin Manager page, in Jenkins:

Click Manage Jenkins, on the left hand-side menu, followed by Manage Plugins on the center view.

Step 2: Select the Git plugins:

Click Available tab, and select the following:

Step 3: Install:

Click Install without Restart at the bottom of the page:

Create a Jenkins Staging deploy job

This job facilitates deployment of code.

Step 1: Create a New Item:

Navigate back to the main Jenkins page, and click Item, on the left hand-side menu.

Step 2: Fill in the form, as per below, and click Ok:

Start editing this job:

Step 1: Configure source code management, to fetch the Capistrano Recipe repository:

NOTE: Add repository credentials, by clicking Add, below Credentials.

Step 2: Add a build step, to trigger the Capistrano deploy task:

Scroll at the bottom of the page, and select the following:


cd $WORKSPACE/citest/ && cap staging deploy

In the following field:

Step 4: Click Save.

Test your Staging deployment job:

By clicking back to Dashboard, you show now see the newly created job:

NOTE: The image above depicts a last successful build, with a couple of failed builds. A new task would not the display the two icons, and time indicators.

Click staging-deploy, followed by Build Now. Progress can be checked here:

Console output can be viewed by clicking the link on the image above, followed by Console Output.

Create a Jenkins Staging test job

This job facilitates deployment, and execution of tests.

Once a task has been created, it can be cloned and parameters changed. 

Click New Item, and select the following:

Click OK, and add edit the shell command to execute:

cd $WORKSPACE/citest/ && cap staging deploy:test

Click save.

Create a Jenkins Staging rollback job

This facilitates the rollback of deployed code.

Similarly to above, clone a job into staging-rollback, and add the following code:

cd $WORKSPACE/citest/ && cap staging deploy:rollback

Create Jenkins Production deploy and rollback jobs

This shows how to replicate the staging deployment jobs for a production environment.

Repeat the clone process, for task production-deploy and production-rollback, and add one line for each:

cd $WORKSPACE/citest/ && cap production deploy
cd $WORKSPACE/citest/ && cap production deploy:rollback

Optional: Create a Jenkins Production / Staging application restart job

Optionally, you can create jobs for restarting applications on production and staging environments.

Clone your production deploy job, and add the following:

cd $WORKSPACE/citest/ && cap production deploy:restart

Leave a Reply

Your email address will not be published. Required fields are marked *