kevicency / MSBuild.NodeTools

Run various node tools as a MSBuild dependency
BSD 3-Clause "New" or "Revised" License
64 stars 14 forks source link

Global NodeJs and TeamCity #8

Open billrawlinson opened 9 years ago

billrawlinson commented 9 years ago

I figure I am just doing something wrong but.. maybe not.

I have an windows 2012 server VM running in Azure cloud with TeamCity. When TeamCity runs the build the MsBuild.NodeTools works fine if I provide the local info for Node.

However, it is really slow becuase of the downloading of various node modules on each build.

So I installed Node globally on the VM at c:\nodejs then added a system environment variable of NODJS which points to c:\nodejs AND it is on the system PATH variable.

Yet I get the error: Global NodeJS installation not found. Please set the 'NODEJS' environment variable for a global installation or set the 'LocalNodePath' property in your project file for a local installation.

I am hoping that with the global node install that it will cache the modules locally so when each build needs them it will just be copying them on the filesystem and not have to re-download them each time (which takes roughly 3.5 minutes).

On my personal machine the build works fine without specifying a local node path and without having a SYSTEM environment variable of NODEJS.

Any help would be appreciated.

EDIT: I've restarted the TeamCity service (just to be on the safe side) but that didn't seem to help.

billrawlinson commented 9 years ago

It appears that restarting the Build Agents worked and now Node is running from the global install.

I'm adding some more info for anyone else who tries this:

  1. Node still won't really install things right away because of some path issues when TeamCity is running as "System" you need to update the global config information for node modules. I used these steps: http://stackoverflow.com/a/26894197/7329

Plus you have to update the PREFIX in the %NODJS%/node_modules/npm/npmrc file

And, even with all of that done it didn't get anything to run any faster. So, it seems the best recourse is just to use the Local settings and to use nuget to get node,npm, etc..

kevicency commented 9 years ago

I don't have any experience with TeamCity but it looks like your node_modules folder gets deleted after each Build or my guess is that TeamCity creates a fresh workspace for each Build and therefore has to download all the node modules again.

npm-cache looks like the way to go in your case but it is currently not supported. You'd have to change the RunNpmCmd property in MSBuild.Npm.targets to use npm-cache install instead of npm install (and globally install npm-cache on your build server).

I'll add support for npm-cache soon™ since it looks like a frequent use case.

billrawlinson commented 9 years ago

Thanks. I'm working on the npm cache solution presently. I think I need to tell it where to put the package cache as part of the npm-cache command. By default it created a directory for the cache in my working directory and it was actually slower than just using npm install. On Feb 15, 2015 8:36 AM, "Kevin Mees" notifications@github.com wrote:

I don't have any experience with TeamCity but it looks like your node_modules folder gets deleted after each Build or my guess is that TeamCity creates a fresh workspace for each Build and therefore has to download all the node modules again.

npm-cache https://www.npmjs.com/package/npm-cache looks like the way to go in your case but it is currently not supported. You'd have to change the RunNpmCmd property in MSBuild.Npm.targets https://github.com/kmees/MSBuild.NodeTools/blob/master/build/MSBuild.Npm.targets to use npm-cache install instead of npm install (and globally install npm-cache on your build server).

I'll add support for npm-cache soon™ since it looks like a frequent use case.

— Reply to this email directly or view it on GitHub https://github.com/kmees/MSBuild.NodeTools/issues/8#issuecomment-74417653 .