Is there any way to manually clear a workspace in Bamboo?
Asked by Ian Bond:

One of our Bamboo plans is a continuous integration build of our product that just performs a simple incremental build (just as a developer would). We recently ran into a problem with our build tool where dependencies were not being tracked correctly which caused the incremental build to fail inappropriately. I fixed the issue but in order for that fix to activate we needed to do a clean build, not an incremental build. On the developer's machines this was easy, we just did clean build or ran 'git clean -xdf' to clear all temporary files, however I don't see any way to do that in Bamboo.

Is there any way to force some sort of cleanup in Bamboo manually to force a clean build? The optimal thing would be to be able to run 'git clean -xdf' to clear the repository of any temporary files, but other are on the table (e.g. wiping the workspace entirely). When we were using Jenkins we had the option to wipe the workspace in these situations.

In this case to fix the issue I RDP'd into the Bamboo machine and manually ran a git clean through a git bash window, however it would be more convenient if it were possible to do this through the web interface.


Answers:
author: Ian Bond
body: As mentioned in my previous comment, this is the best I could come up with.

After playing around with this a bit more, one solution that I came up with is to define a Bamboo variable "ManualClean" that is 0 by default and add a Script that is passed ${bamboo.ManualClean} as a parameter and contains:

<br />

if "%1"=="1" git clean -xdf

If I want to perform a completely clean build I can "Run Customized..." and set that ManualClean parameter to 1. It works, but it'd be nice to not have to do this with every one of our builds.


author: Colin Goudie
body: Under each task, in the Source Checkout task, you can select the option to 'force clean build' But then you need to run the build, then uncheck it again. Bit of a pain

I also thought there was a clear git cache somewhere but I can't seem to find it now in Bamboo 4 and also wasn't too sure what it did anyway ;)


author: Krystian Brazulewicz
body: On demand cleaning of working directory can be achieved in the following way:

- add "clean.run" variable to your plan and set it to "false"

- add "Clean working directory" task as the first task in your job

- tick "Conditional task" and configure it so "clean.run" set to "true" will trigger task execution

- use "Run customised" to run your plan and override "clean.run" variable to true


author: David Penney
body: I am looking for something similar. Because changes to .h files do not always trigger a rebuild correctly (C/C++) I had a system in place that would do a nightly clean rebuild before the deveopers arrived in the morning. This would ensure that the CI environment was providing the best information on the state of the repository firs thing in the morning.

What I would like to see is an option in the trigger section that would allow a scheduled build or manual build to momentarilty set the 'Force Clean Rebuild' flag. That way I could have the code checking builds rebuilding on top of what is there and the cron job could set the 'Force Clean Rebuild' flag when it runs overnight. It would/could also let someone run a manual customized build and set the flag for that execution trigger only.

comments: author: benson margulies
body: I want to be able to set 'force clean build' as part of a customized manual run.


author: Tyler Mace
body: ... or a scheduled run. It's what David Penney is talking about.


author: Tyler Mace
body: As a SubVersion user of Bamboo, we don't have a simple command we can run on Windows workstations. (we have svn-clean on Linux) This is really a missing piece of the "Run custom..." dialog, where it gives the user the option to define an SVN version number. Why not also offer this checkbox?

The reality is, that in the proposed solution here, to hit that checkbox, you only need to do it once in a great while. Usually, you need not do a clean-build. But to do a clean build is really the workflow of a custom-build. It should just be a feature embedded in Bamboo. Coming soon to feature requests.

<https://jira.atlassian.com/browse/BAM-15479>


author: PiotrA
body: I'd try what Colin suggests - tick "force clean build" checkbox in the relevant Source Checkout task(s).

![](http://img42.imageshack.us/img42/6461/20120510104529761x493sc.png)


author: Ian Bond
body: After playing around with this a bit more, one solution that I came up with is to define a Bamboo variable "ManualClean" that is 0 by default and add a Script that is passed ${bamboo.ManualClean} as a parameter and contains:

<br />

if "%1"=="1" git clean -xdf

If I want to perform a completely clean build I can "Run Customized..." and set that ManualClean parameter to 1. It works, but it'd be nice to not have to do this with every one of our builds.


author: Keith Miller
body: Why not create an Ant task that does the Git command and create a new job to run it? That way you can run it from Bamboo whenever you want.

comments: author: Ian Bond
body: I'm under the impression that each job gets its own copy of the git repository so a new job would be working from a different repo. Or am I not understanding some detail here? (I've never used Ant so I'm not sure if that's a factor here)


author: Keith Miller
body: Hmm, it looks like you are correct. What you can do is go to the Bamboo machine, get the path of the first job, and then use that path with the git command in your Ant task. That way you can run it from a separate job whenever you want.

Here is an example Ant script:

```
&lt;project name="yourname" default="git-clean" basedir="."&gt;        &lt;target name="git-clean"&gt;        &lt;exec dir="/opt/bamboo-agent-home/xml-data/build-dir/PLAN-BUILD-JOB1" executable="git"&gt;          &lt;arg line="clean -xdf"/&gt;        &lt;/exec&gt;    &lt;/target&gt;&lt;/project&gt;
```

Just replace the exec dir with where your build is located. I just recommend Ant because running command line tasks in Bamboo is so easy with it.