Continuous deployment of node.js apps with Jenkins and Git

Reading time ~1 minute

First of all, thanks to carbonsilk for providing the first tutorial on how to configure automated deployment with Git and Jenkins.

But things have changed since 2011 so I’d like to share my simplified setup on automated (continuous) deployment of node.js applications with forever, git and jenkins. I’m using BitBucket in the example, you can just exchange the hostname with github.com for github repositories.

  • As root/sudo:
sudo apt-get install jenkins

(open port 8080 in your firewall)

sudo npm install -g express connect karma forever
  • As user 'jenkins' (sudo su jenkins)
git config --global user.name 'Jenkins'
git config --global user.email 'info@yourapp.com'
ssh bitbucket.org -l git (add the server to the list of authorised hosts)
ssh-keygen -t rsa && cat ~/.ssh/id_rsa.pub
  • Jenkins Web (http://yourserver:8080)
  1. Manage Jenkins - Manage Plugins - Search 'Git' - Install GIT plugin
  2. Manage Jenkins - Configure System - Enable security - Jenkins's own user database (Allow signup) - Logged-in users can do anything
  3. Register your user (remove Allow signup afterwards in the config)
  4. Add Job - 'Build a free-style software project'
  5. Source Code Management: Git (Repository URL: git@bitbucket.org:team/project.git)
  6. 'Check Trigger builds remotely' (e.g., from scripts) and add random long password.
  7. Execude Shell:
    npm install
    npm update
    forever stopall
    BUILD_ID=dontKillMe NODE_ENV=production forever start app.js
    • Go to Git provider (BitBucket, GitHub) and add Jenkins Service.
    Get your API token from jenkins in your user profile and add it to your git scm: http://yourjenkinsname:abc123abc123abc123abc123@yourcoolnewappserver:8080/ Project name: your-app Token: the-random-long-password-you-defined-in-jenkins Done.health-80plus

Europe on Two Wheels

![Iron 883](/images/2015/07/IMG_7368.jpg)## Barcelona (Spain) - Le Dramont, Cote d'Azur (France)> 648km![Le Dramont](/images/2015/07/IMG_...… Continue reading

Updates!

Published on September 10, 2014

HTML5 vs. Native [thoughts]

Published on February 26, 2014