# Jenkins freestyle project workspace cleanup

**URL:** <https://community.jenkins.io/t/jenkins-freestyle-project-workspace-cleanup/5007>\
**Category:** Using Jenkins\
**Created:** [December 17, 2022, 4:02pm UTC](https://community.jenkins.io/t/jenkins-freestyle-project-workspace-cleanup/5007 "2022-12-17T16:02:57Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![sftiit](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/sftiit/32/2591_2.png) [@sftiit](https://community.jenkins.io/u/sftiit)\
**Post date:** [December 17, 2022, 4:02pm UTC](https://community.jenkins.io/t/jenkins-freestyle-project-workspace-cleanup/5007/1 "2022-12-17T16:02:57Z")

</div>

How do I cleanup the workspace declaratively? I’m not using any jenkinsfile and it’s not a pipeline. Thanks.

---

<div class="post-metadata">

**Author:** ![MarkEWaite](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/markewaite/32/20_2.png) [@MarkEWaite](https://community.jenkins.io/u/MarkEWaite)\
**Post date:** [December 17, 2022, 5:07pm UTC](https://community.jenkins.io/t/jenkins-freestyle-project-workspace-cleanup/5007/2 "2022-12-17T17:07:57Z")

</div>

Darin Pope provides a 15 minute video that reviews alternatives to delete build history in case that is what you mean by “cleanup the workspace declaratively”.

[![](https://europe1.discourse-cdn.com/flex013/uploads/jenkins/original/2X/3/31c2ebf877b688f908cd9aa758afa75b85ce2f40.jpeg "How to Clean up Old Jenkins Builds") ](https://www.youtube.com/watch?v=_Z7BlaTTGlo)

If you mean something different, please explain in more detail what you mean by “cleanup the workspace declaratively”.

---

<div class="post-metadata">

**Author:** ![sftiit](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/sftiit/32/2591_2.png) [@sftiit](https://community.jenkins.io/u/sftiit)\
**Post date:** [December 17, 2022, 5:53pm UTC](https://community.jenkins.io/t/jenkins-freestyle-project-workspace-cleanup/5007/3 "2022-12-17T17:53:27Z")

</div>

Sorry, I did not make it clear. My freestyle project checks out the code in the below dir when I kick off a build. Once the build job is done, I’d like to clear the contents in the workspace directory.

I have a c:\jenkins\workspace directory in the slave machine.

---

<div class="post-metadata">

**Author:** ![halkeye](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/halkeye/32/8_2.png) [@halkeye](https://community.jenkins.io/u/halkeye)\
**Post date:** [December 17, 2022, 6:47pm UTC](https://community.jenkins.io/t/jenkins-freestyle-project-workspace-cleanup/5007/4 "2022-12-17T18:47:31Z")

</div>

there’s a checkbox on the top of freestyle jobs that says cleanup workspace before/after/etc  
assuming you have the cleanup workspace plugin installed.

---

<div class="post-metadata">

**Author:** ![sftiit](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/sftiit/32/2591_2.png) [@sftiit](https://community.jenkins.io/u/sftiit)\
**Post date:** [December 17, 2022, 9:12pm UTC](https://community.jenkins.io/t/jenkins-freestyle-project-workspace-cleanup/5007/5 "2022-12-17T21:12:17Z")

</div>

There is an option “Delete workspace before build starts” checkbox. Does this option wipe out everything under c:\jenkins\workspace directory? I’d like to keep some config files which are not part of the code repository. I’d like to delete only the files checked out by Jenkins.

---

<div class="post-metadata">

**Author:** ![mawinter69](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/mawinter69/32/1625_2.png) [@mawinter69](https://community.jenkins.io/u/mawinter69)\
**Post date:** [December 18, 2022, 9:39am UTC](https://community.jenkins.io/t/jenkins-freestyle-project-workspace-cleanup/5007/6 "2022-12-18T09:39:39Z")

</div>

For freestyle jobs there is a post build step “Delete workspace when build is done” provided by the workspace cleanup plugin  
Here you can define exactly what should be deleted and under which conditions (success, failure, …).
