I have a NodeJs application. I have a Jenkins job that does the gollowing:
I'm looking for ways to improve the build. Some of my ideas
Is there anything else I can do to improve the time of the build?
Some good ideas - here's what I would also consider:
First, try to measure how long each step (cloning, npm install
, run tests, ...) takes, and then try to work on improving each step. You can either try to focus on the one that's taking up most of the time, or you can try to get some quick wins before trying to crack the harder nuts.
Some ideas:
git clone
every time? Maybe consider doing a git pull
instead. At the end of the build, do a git reset --hard ; git clean -f -d
as the last step to get rid of any uncommitted or locally changed files. I found that doing this is a lot faster than doing a full git clone
every time.npm install
: In line with the above step, if you keep the node_modules
folder from the previous build, this step should be a lot quicker as well. There is of the course the risk of updates or removed dependencies, which will still linger around. Many code changes don't require you to reinstall all of the node modules. You might even be able to put in a bit of logic that detects whether the package.json
file has changed since the last build, and only run a full npm install
in that case.git clone
and a full npm install
once per day. All other builds during the day use the previous build state and are a lot quicker as a result of this. If you find that this leads to wrong results, you could schedule the clean build to run several times per day.s3cmd
/aws command - I think these can work in a similar way as rsync
, which can be really fast and efficient if used the right way. Only try to the git diff
route as a last resort. Doing a git pull
instead of a git clone
might already solve this issue.These are some initial ideas that I would try as a first step.
Performing a shallow clone speeds up the cloning part. As it does not download all commits.
git clone --depth 1 clone_url...
You should be able to cache node_modules
with this plugin: https://plugins.jenkins.io/jobcacher
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With