5

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?

m90
  • 11,434
  • 13
  • 62
  • 112
  • possible duplicate of [TeamCity build runner not recognizing executable](http://stackoverflow.com/questions/16429794/teamcity-build-runner-not-recognizing-executable) – m90 Nov 07 '13 at 16:03

2 Answers2

6

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.

Community
  • 1
  • 1
deadlydog
  • 22,611
  • 14
  • 112
  • 118
  • I actually ended up (as is the question marked as duplicate) to have my BuildAgent run as a distinct user that does have its own install of grunt-cli. Now I am running into other problems though: The grunt process randomly fails (it just stops), yet returns a 0 so deployment will continue. Do you have issues like this by any chance? – m90 Nov 15 '13 at 19:48
  • @m90 I just implemented this yesterday, but I haven't noticed any problems yet. If I do I'll let you know. Thanks for the heads up. – deadlydog Nov 15 '13 at 20:41
2

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.

PotOfTea
  • 213
  • 3
  • 12
  • I didn't manage to install that properly. I placed the ZIP into the folder and triggered a restart of the service, but nothing ever happened. – m90 Nov 11 '13 at 08:36
  • You are speaking about plugin? What version of Teamcity you are using? In Teamcity Administration > Plugin List, do you see there "Node.js build runner"? – PotOfTea Nov 11 '13 at 10:39