5
votes

I'm trying to automate building of my project on a TeamCity server. I'm using grunt to define and configure my tasks. This works fine locally. Yet, I am having problems getting TeamCity (running on Windows Server 2008) to recognize grunt as a executable, the build will fail when grunt is called as it is not available.

I do have grunt-cli installed on the server and can execute it when I login via ssh (The build script also succeeds when I trigger it that way).

I'm running npm install before I call grunt and also tried to force install grunt-cli using a preinstall instruction in my package.json like:

{
  "name": "someName",
  "version": "0.0.1",
  "private": true,
  "scripts" : {
    "preinstall" : "npm install grunt-cli -g"
  },
  "devDependencies": {
    "grunt": "~0.4.1",
    "grunt-contrib-jshint": "~0.6.3",
    "grunt-contrib-less": "~0.8.1",
    "grunt-contrib-watch": "~0.5.3",
    "grunt-contrib-requirejs": "~0.4.1",
    "grunt-strip": "~0.2.1",
    "grunt-bump": "0.0.11"
  } 
}

I can see npm installing grunt-cli, yet grunt is not available in the next step.

I also tried wrapping that into a bat file or using multiple build steps for dependency installing and running the grunt task.

Does anyone have any input on this?

2

2 Answers

6
votes

I had the same problem when trying to get our TFS Build agents to run grunt-cli. In the end I just changed my build process to use the full path to the grunt-cli executable.

So I changed from using this:

grunt deploy

to using this:

"C:\Users\tfsservice\AppData\Roaming\npm\grunt.cmd" deploy

I know this is just a workaround and not a true fix, but it should be good enough to get you going. I hope this helps.

-- Update --

I was able to get it to work properly by simply adding "C:\Users\tfsservice\AppData\Roaming\npm" (where the grunt.cmd file is found) to my system path, and then rebooting my build server. The reboot was required since tfsservice is both a user and a running service; simply restarting the service may be enough, but I didn't test that.

After doing this grunt deploy worked in our builds as expected.

2
votes

You are running Teamcity agent on Widnows Server? There is plugin for Node.js/Grunt for Teamcity: https://github.com/jonnyzzz/TeamCity.Node As far as I've used it had no issue running grunt with Teamcity.