Reset / clean workspace between pipeline steps

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?

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

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:

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.

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:

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)?

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.

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.

1 Like

Sure, you can close it now if you want.