Recently, I was asked for help to alter one of our builds to “run dirty”. They use npm and were incurring a significant cost by starting with a fresh checkout on every build. By leaving the node_modules diretory around between builds, it would shave 4 minutes off the build time.
While I could have simply unchecked “Force Clean Checkout” on our Source Code Checkout task in Bamboo, that would have made dealing with the occasional need to do a clean build a bit awkward. In order to do a clean build, someone would have to:
- Have admin rights on the plan
- Edit the definition to check “Force Clean Checkout”
- Run a build
- Then (hopefully) remember flip it back again.
A bit clunky… plus it would affect all builds, not just the single branch that needed the clean build.
What I wanted was a push button method for someone with build rights to force a clean build on a single branch. Here’s how it works:
- Add a plan variable, force_clean, with a value of false.
- Add a Script task before the Source Code Checkout task. In it, check if force_clean = true, then clean the working directory.
- Now to force a clean build, use “Run Customized…” and override force_clean to true! Simple.