TeamCity and avoiding redownloading of npm packages

I haven’t been able to find a better solution that this. My original post on stackoverflow here.

TeamCity clears out the node_modules folder on every build, so when running npm install it re-downloads them all. So I’ve moved to using a powershell step to backup and restore this folder and the end and start of each build respectively.

Here is the PS step i run at the start


param (
[string]$projId ,
[string]$WorkDir
)

if(Test-Path "c:\node_backup\$projId\node_modules")
{
Move-Item "c:\node_backup\$projId\node_modules" "$WorkDir\node_modules"
}

And here is the one at the end


param (
[string]$projId ,
[string]$WorkDir
)
If (!(Test-Path "c:\node_backup"))
{
mkdir "c:\node_backup"
}
If (!(Test-Path c:\node_backup\$projId))
{
mkdir "c:\node_backup\$projId"
}
If (Test-Path "c:\node_backup\$projId\node_modules")
{
Remove-Item "c:\node_backup\$projId\node_modules"
}

Move-Item "$WorkDir\node_modules" "c:\node_backup\$projId"

Then in the script arguments i pass this

-projId %system.teamcity.buildType.id% -WorkDir %NodeWorkingDirectory%

The NodeWorkingDir is a parameter I set in my projects that i use to tell node where my gulp file is.

 

4 thoughts on “TeamCity and avoiding redownloading of npm packages

  1. I have tried using your suggestion but in teamcity, it is not allowed to use remove-item or move-item in powershell. how do you resolve it?

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s