Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Jenkins, is there a way to persist npm packages so I don't have to install them in each build?

I'm using Jenkins (CloudBees) to build my project, and this runs some scripts in each build to download some node packages using npm. Yesterday the npm registry server was having troubles and this blocked the build cycle of the project.

In order not to depend on external servers, is there a way to persist my node_modules folder in Jenkins so I don't have to download them in every build?

like image 403
farolfo Avatar asked Nov 01 '22 11:11

farolfo


1 Answers

You can check the package.json file and backup node_modules directory.

When you start next build in jenkins, just check package.json file and node_modules backup, if package.json file is not changed, just using previous backup.

PKG_SUM=$(md5sum package.json|cut -d\  -f 1)
CACHED_FILE=${PKG_SUM}.tgz
[[ -f ${CACHED_FILE} ]] && tar zxf ${CACHED_FILE}
npm install
[[ -f ${CACHED_FILE} ]] || tar zcf ${CACHED_FILE} node_moduels

above is quite simple cache implementation, otherwise you should check the cache file is not damaged.

like image 146
Guixing Bai Avatar answered Nov 09 '22 11:11

Guixing Bai