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.
This is great. Short, to the point and perfectly formed for TeamCity.
Only alteration I’ve made is to use a shared directory so that the build can execute on any agent.
Thanks!
LikeLike
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?
LikeLike
I haven’t had this issue before sorry. I would check the configuration of your build agents, perhaps you have a file permission issue that is making it fail
LikeLike
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?
LikeLike