Configurable Builds: One configuration file per machine
I’ve covered some of the ways that I’ve seen for making builds configurable in previous posts:
One which I haven’t covered which my colleagues Gil Peeters and Jim Barritt have pointed out is having a build with one configuration file for each machine.
Again the setup is fairly similar to one configuration per user or environment. Using Nant we would have the following near the top of the build file:
<property name="machine.name" value="${environment::get-machine-name()}" />
<include buildfile="${trunk.dir}\config\${machine.name}.properties.xml" />
We could then have one configuration for each developer machine:
machine1.properties.xml
<?xml version="1.0" ?>
<properties>
<property name="property1" value="onevalue" />
</properties>
machine2.properties.xml
<?xml version="1.0" ?>
<properties>
<property name="property1" value="anothervalue" />
</properties>
The build file can be run using the following command:
nant -buildfile:build-file.build target-name
The benefit of this approach can be seen (as Gil points out) in pair programming where the settings on any one machine will always be the same regardless of who is logged in. We also still get the advantage of being able to use remote resources on developer machines.
Having machine specific configuration also allows more flexibility for configurations on continuous integration for example. To quote Gil:
Each CI build (multiple builds per build server) get’s it’s own [configuration] based on the build host and build name.
The disadvantage again is we have to add a new configuration file every time we want to run the build on a different machine.
About the author
I'm currently working on short form content at ClickHouse. I publish short 5 minute videos showing how to solve data problems on YouTube @LearnDataWithMark. I previously worked on graph analytics at Neo4j, where I also co-authored the O'Reilly Graph Algorithms Book with Amy Hodler.