# Reset / clean workspace between pipeline steps

**URL:** <https://drone.discourse.group/t/reset-clean-workspace-between-pipeline-steps/11045>\
**Category:** Drone Support\
**Created:** [September 6, 2017, 1:35am UTC](https://drone.discourse.group/t/reset-clean-workspace-between-pipeline-steps/11045 "2017-09-06T01:35:00Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![ozbillwang](https://yyz1.discourse-cdn.com/flex003/user_avatar/drone.discourse.group/ozbillwang/32/3947_2.png) [@ozbillwang](https://drone.discourse.group/u/ozbillwang)\
**Post date:** [September 6, 2017, 1:35am UTC](https://drone.discourse.group/t/reset-clean-workspace-between-pipeline-steps/11045/1 "2017-09-06T01:35:00Z")

</div>

Our pipelines are:

Unit test (which include, install packages, run a lot of test cases, generate cache files, etc).

If the unit test works fine, I need a step to refresh the environment as new (remove all cache and generated files)

Then I can run `docker build` from the fresh code directly.

How to do that? How to set the pipeline to clean the environment first, then run the `docker build` command?

---

<div class="post-metadata">

**Author:** ![bradrydzewski](https://yyz1.discourse-cdn.com/flex003/user_avatar/drone.discourse.group/bradrydzewski/32/3513_2.png) [@bradrydzewski](https://drone.discourse.group/u/bradrydzewski)\
**Post date:** [September 6, 2017, 2:05am UTC](https://drone.discourse.group/t/reset-clean-workspace-between-pipeline-steps/11045/2 "2017-09-06T02:05:15Z")

</div>

If I want to clean my project directory locally (on my laptop) I would do something like this:

```auto
npm install # download dependencies
npm run test # execute test suite
rm -rf node_modules # delete dependencies folder
npm install # re-download dependencies

```

This approach can be translated directly to your pipeline configuration:

```diff
pipeline:
  test:
    image: node
    commands:
      - npm install
      - npm run test
+ - rm -rf node_modules
+ rebuild:
+ image: node
+ commands:
+ - npm install

```

There is no automagic way for drone to reset your workspace in-between pipeline steps. This is something you will need to handle manually in your yaml, similar to how you would handle this locally form the command line.

---

<div class="post-metadata">

**Author:** ![ozbillwang](https://yyz1.discourse-cdn.com/flex003/user_avatar/drone.discourse.group/ozbillwang/32/3947_2.png) [@ozbillwang](https://drone.discourse.group/u/ozbillwang)\
**Post date:** [September 6, 2017, 2:20am UTC](https://drone.discourse.group/t/reset-clean-workspace-between-pipeline-steps/11045/3 "2017-09-06T02:20:43Z")

</div>

Not sure I like it. Anyway, thanks for the solution.

Since the projects are different, python, node, golang, java, or others, `rm -f` doesn’t always work, because I don’t know where are these temp files generated.

I’d like to find a generic way to deal with it. I prefer if Drone team can develop a new feature that we can active/nominate some pipeline steps in a new/seperate workspace, or totally different agent

an extra option as below:

```diff
pipeline:
  test:
    image: node
    commands:
      - npm install
      - npm run test
  rebuild:
    image: node
    commands:
      - npm install
+ workspace: new

```

Do you think that’s a good idea? Should we include this feature in GA release (1.0)?

---

<div class="post-metadata">

**Author:** ![ozbillwang](https://yyz1.discourse-cdn.com/flex003/user_avatar/drone.discourse.group/ozbillwang/32/3947_2.png) [@ozbillwang](https://drone.discourse.group/u/ozbillwang)\
**Post date:** [September 6, 2017, 2:22am UTC](https://drone.discourse.group/t/reset-clean-workspace-between-pipeline-steps/11045/4 "2017-09-06T02:22:21Z")

</div>

I am thinking to run the unit test in virutual environment (a docker container) as well, such as `kitchen test` if Drone doesn’t support this feature currently.

---

<div class="post-metadata">

**Author:** ![bradrydzewski](https://yyz1.discourse-cdn.com/flex003/user_avatar/drone.discourse.group/bradrydzewski/32/3513_2.png) [@bradrydzewski](https://drone.discourse.group/u/bradrydzewski)\
**Post date:** [September 6, 2017, 2:53am UTC](https://drone.discourse.group/t/reset-clean-workspace-between-pipeline-steps/11045/5 "2017-09-06T02:53:13Z")

</div>

The yaml configuration format is largely frozen at this time. I recommend using the approach defined above, where you manually purge the workspace with shell commands.

---

<div class="post-metadata">

**Author:** ![ozbillwang](https://yyz1.discourse-cdn.com/flex003/user_avatar/drone.discourse.group/ozbillwang/32/3947_2.png) [@ozbillwang](https://drone.discourse.group/u/ozbillwang)\
**Post date:** [September 6, 2017, 2:54am UTC](https://drone.discourse.group/t/reset-clean-workspace-between-pipeline-steps/11045/6 "2017-09-06T02:54:46Z")

</div>

Sure, you can close it now if you want.

---

<div class="post-metadata">

**Author:** ![bradrydzewski](https://yyz1.discourse-cdn.com/flex003/user_avatar/drone.discourse.group/bradrydzewski/32/3513_2.png) [@bradrydzewski](https://drone.discourse.group/u/bradrydzewski)\
**Post date:** [September 6, 2017, 2:55am UTC](https://drone.discourse.group/t/reset-clean-workspace-between-pipeline-steps/11045/7 "2017-09-06T02:55:07Z")

</div>

Closed on September 6, 2017, 2:55am UTC


