43

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"
Stevoisiak
  • 23,794
  • 27
  • 122
  • 225

4 Answers4

108

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.

André Laszlo
  • 15,169
  • 3
  • 63
  • 81
thomaux
  • 19,133
  • 10
  • 76
  • 103
  • @Anzeo Should all other grunt task libraries required be part of devDependencies or dependencies? I noticed I still get build error saying "npm module not found", for instance, for "grunt-contrib-watch" – theunexpected1 May 27 '15 at 14:02
  • @theunexpected1 normally all your grunt tasks should be listed as development dependencies. Are you sure the contrib-watch is listed in the package.json? – thomaux May 27 '15 at 19:51
  • 1
    @Anzeo, yeah, sure about that. I haven't gone much further to debug, for now, I have removed grunt build from the postinstall process. I'll get back once I try it again, thanks. – theunexpected1 May 27 '15 at 20:11
8

You likely miss in your travis.yml file:

before_script:
  - npm install -g grunt-cli

Then "grunt whatever" should execute ok (assuming you do require grunt in your devDependencies in your package.json).

(see http://www.mattgoldspink.co.uk/2013/02/10/using-travis-ci-with-grunt-0-4-x/)

Mangled Deutz
  • 11,384
  • 6
  • 39
  • 35
0

Make sure that you have grunt as part of your devDependencies. Here is a sample file: https://github.com/fraxedas/raspi-cloud/blob/master/package.json

"devDependencies": {
  "grunt": "^0.4.5",
  "grunt-contrib-jshint": "^0.11.2",
  "grunt-contrib-watch": "^0.6.1"
}

Travis-ci will install grunt on the install step:

npm install 
...
grunt@0.4.5 node_modules/grunt
...

In my case I wanted to run jshint with grunt. Here is my travis.yml file: https://github.com/fraxedas/raspi-cloud/blob/master/.travis.yml

To integrate grunt all I needed was:

before_script: grunt jshint

You can change jshint by another command.

Oscar Fraxedas
  • 4,467
  • 3
  • 27
  • 32
0

My .travis.yml looks like this:

It runs much faster than npm as NodeJSpackage manager, I'm using Yarnon this example. It installs yarn, grunt cli, rubyand sass.

Hopefully it helps.


  language: node_js

  node_js:
    - "7.1.0"

  before_install:
    - npm install -g yarn
    - yarn add global ruby
    - gem install sass

  install:
    - yarn add global sass
    - yarn add global grunt-cli
    - yarn add yarn install

 before_script: grunt

Thiago Lima
  • 21
  • 1
  • 4