Yeoman && Wercker && Heroku

Wercker is a continuous integration service that lets you use private bitbucket repos for no cost. I like the way they do things and see a lot of potential with the service.

A few weeks ago I wrote a post about using Yeoman, Travis-Ci, and Heroku. I have since used that method for a few more projects and it worked well.

Last week I started working on a small team project that we did not want to be completely open source, but we still wanted to deploy upon successful build. Using Travis-Ci with private GitHub repos is too expensive for us right now.

After some quick research we settled on using bitbucket for source code management and wercker for continuous integration. At the time of this post both were free and private for our purposes.

Wercker Basics

Wercker uses the concepts of boxes, which are preconfigured machines, and steps to perform its ci duties. The solution I am going to describe is not optimized to use prebuilt boxes and steps, but that is something I plan on doing in the future.


We want wercker to do the following on every commit to bitbucket:

  • run the defined tests
  • if the tests pass and the branch is master
  • build the yeoman project deploy to heroku
  • Sounds simple enough.


The fist thing to configure is your wercker.yml file.

Grunt and Bower

The default wercker/nodejs box does not have bower and grunt installed, so be sure to include them.

- script: name: install bower grunt run bower code: |- npm install bower grunt-cli node_modules/bower/bin/bower install

Add to known hosts

This is a prebuilt wercker step that lets us deploy to heroku without a bunch of warnings.

- add-to-known_hosts: hostname:

Make deploy script executable and execute

It is a best practice to execute long scripts in a separate file to keep the yml file clean and more modular. We will be executing the script.

Note that we are only executing on commits to the master branch. This lets the team develop on feature branches on the main repo.

- script: name: deploy code: |- chmod u+x if [[ $WERCKER_GIT_BRANCH == "master" ]]; then ./; fi

Complete wercker.yml

box: wercker/nodejs services: - wercker/mongodb # Build definition build: # The steps that will be executed on build steps: - npm-install - script: name: run bower code: node_modules/bower/bin/bower install - npm-test - add-to-known_hosts: hostname: - script: name: deploy code: |- chmod u+x if [[ $WERCKER_GIT_BRANCH == "master" ]]; then ./; fi

Grunt Build

grunt build

This code builds the project in the dist/ folder

Move to Dist Folder

cd dist
git config --global "[your email address]" git config --global "[your name]"

Install Heroku CLI

sudo gem install heroku

Manage Heroku Keys

Here we clear the existing ssh keys from heroku and then add a new one.

heroku keys:clear yes | heroku keys:add

Git Magic

Here we setup the git repo and then commit to heroku

git init git add . git commit -m 'deploy' git remote add heroku [your heroku git repo] git push heroku master -f

Clean Up

heroku keys:clear

Complete Script

grunt build cd dist git config --global "" git config --global "Casey" sudo gem install heroku heroku keys:clear yes | heroku keys:add git init git add . git commit -m 'deploy' git remote add heroku git push heroku master -f heroku keys:clear echo "...done."

Originally published at

Copyright © 2020.