Run grunt build command on Travis CI

user2693845 picture user2693845 · Jan 15, 2014 · Viewed 11.1k times · Source

I am using Travis CI to test and build my project and as part of it I want travis to run grunt build i have tried the following but have had no luck.

  • script: "grunt build"
  • script: "./node_modules/grunt build"
  • script: "./node_modules/grunt/grunt build"
  • script: "./node_modules/grunt/grunt.js build"

Answer

thomaux picture thomaux · Jan 15, 2014

Have you made sure to install grunt-cli globally on your Travis node?

My Travis CI config looks like:

language: node_js
node_js:
  - "0.8"
before_install: npm install -g grunt-cli
install: npm install
before_script: grunt build

And my package.json:

{
    ...
    "scripts": {
        "test": "grunt test"
    },
    ...
}

I will explain the flow of steps that Travis will execute:

  1. The first step to be executed is the before_install. My only prerequisite (besides node.js) is grunt-cli so I use this step to install it.
  2. Next is the install step, in my case this will simply install my npm modules
  3. The before script is then executed, running grunt build
  4. Lastly Travis will look for scripts in the package.json, there I indicated the test step should run grunt test

I'd like to note that this is my own opinion on how to configure Travis. I'm certainly not inclining you should use exactly the same approach.