Build

Building software projects is hard. Here are some best practices: Make it fast

There is the continuous struggle between make it right and make it fast. Some buildsystems promise to combine both goals.

Make dev builds superfast

We all know that multitasking is evil. Every build that runs longer than 10s

Clone shallow vs. Clone full

Normally a buildserver is not interested in the history of the repository. On the other hand it needs some context, to show what was changed. For me the best option is a shallow clone, that can be also used to incrementally pull. Because a pull with not much changes will still be faster than a full shallow clone.

Keep the buildfile as small as possible

The build should be as simple as possible. e.g. make is better than make clean generate build test release

All parties should use one buildfile

The buildfile should work for all parties. Its a wide range from developers to buildservers. If all use the same, errors are found earlier on and the project makes sure that all important steps are in git.

Bring your own tools

My first choice is to not depend on preinstalled tools but put everything into the workspace and make it self contained. Another option is using docker images, but this has another set of drawbacks.

Try to avoid gaps/bridges between buildsystems

Every gap between different buildsystems makes the whole image less correct / efficient. E.g. recursive make considered harmful.

Build out of source

Put all build artifacts to a common folder structure that is outside of the source folders. This makes your gitignore files very straight forward + you do not even need a clean buildstep, because you just can delete one folder.

Keep your logs down

Make your buildlogs meaningful. Reduce warnings, remove debug output.

Keep only what you need - aka jenkins archives

The results of a build should be as compact as possible. Saving everything without a requirement is not fast and not cheap.

Let the buildserver scale your build

Do not hardcode -j16 or something into your build. This should be possible for the buildservers to decide. They know best what resources they have and how many parallel jobs they have to serve.

Dirty but fast

A viable compromis might be to do some edges of the build in a dirty way, if it really brings speed. E.g. create dockerimages with a snapshot, so that not all work has to be done from scratch.