I am trying to automate the build process of my projects (both java and .net) using Ant and MSBuild. I’ve read about them and know how to write build scripts in Ant and MSBuild. But I wonder, is there any guidelines or best practices for writing build scripts in general? Here are two that I’ve found, but I would like to hear more from other developers.
- In writing a build script, just rely on the items that are located in the source control and are available in the working folder while checking out the sources. Do NOT write build scripts that are dependent on items that are not kept on source control.
- If a project contains a set of sub-systems and each sub-system has its own build scripts, the build file of the project should just call the build scripts of sub-systems. In addition, these files should import a common build file that contain targets such as compile, test, package etc.
I've seen this post as well, but it is detailed on the way of writing tasks. I need more high level guidelines, as mentioned above.
Here are the guidelines I collected from answers:
- Run every build in a clean environment. It means that each build script needs a
clean
target. - Build scripts should usually include
compile
,package
andtest
targets. - If a product have different development lines (e.g. dev , release), all of them should have the same build script. But, different parameters should be passed to these scripts.
- Builds performed on development lines usually contain compiling, packaging, deploying and installing steps. But builds on release lines include further steps, such as tagging the product and generating change-logs/release notes.
- Build scripts should be kept on source control as well.
- try to keep all build information in build scripts, not on continuous integration server (Bamboo, TeamCity, etc.)
- If your build uses a parameter that may change in future (e.g the network address to copy the build results), do not hardcode it into your build script. instead, use build parameters to control it more easily.