Carolyn Van Slyck

A Better Force Clean Checkout in Bamboo

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:

  1. Have admin rights on the plan
  2. Edit the definition to check “Force Clean Checkout”
  3. Run a build
  4. 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:

  1. Add a plan variable, force_clean, with a value of false.


  1. Add a Script task before the Source Code Checkout task. In it, check if force_clean = true, then clean the working directory.


  1. Now to force a clean build, use “Run Customized…” and override force_clean to true! Simple.