Search code examples
node.jsbuildnpmteamcity

Nodejs npm step downloads packages on every build in TeamCity


I'm a bit of a n00b when it comes to nodejs npm, but since implementing it in our build environment using steps recommended on several articles its tripled our build times.

We use it for the standard stuff (minify/concat/etc js/css/etc)

We use TeamCity and have added a Node.js NPM step then a gulp step to run the tasks (RE: https://github.com/jonnyzzz/TeamCity.Node)

The task to setup NPM takes the most time, 2min 10 seconds, which is over 65% of the total build time calling the command "npm install", which appears to re-download all the packages on each build

Step 3/7: NPM Setup (Node.js NPM) (2m:10s)

[npm install] Starting: cmd /c npm install

Out total build times before were around 1min 30sec, including unit tests.

is there anyway to cache these locally and prevent re-download on each build? in the user profile or something maybe as opposed to the build folder?

More detail..

This probably best explains the setup http://www.dotnetcurry.com/visualstudio/1096/using-grunt-gulp-bower-visual-studio-2013-2015

We have C# projects that are using the new Task Runner Explorer, Dependencies are saved into a package.json by this, you pre-run "npm install" once on your local environment in you workspace (need to use a .tfignore to prevent it from checking in to source) then not again, unless you start a new local workspace.

When the build run it needs to run "npm install" from the command line and it picks up dependencies from the package.json file and installs them into a sub folder inside the working directory of the build every time, even if the files are already there from a previous build(i.e. TC agent hasn't cleaned them up), afaik you cant install them outside the working folder.

I could be wrong... Or I should say I hope I'm wrong, and looking for a way for gulp to support this, but what ever way we make it work will need to work with task runner explorer so the F5 experience for the dev is still the same on their local.

We do have multiple agents yes.


Solution

  • The best way i found to fix this was to backup/restore the node modules folder, i've done a blog post about it here

    https://beerandserversdontmix.com/2016/06/04/teamcity-and-avoiding-redownloading-of-npm-packages/