Removing cloned repository after CI build

Hi folks,

I’m trying to setup gitlab runners to enable tests to be run before committing code to our repo.

So far so good, I’ve got the runner configured, running the tests and correctly indicating if a branch can be merged.

My issue however is after the tests are run, there is a new folder in my repo called builds which has a clone of the repository. Is there a way for me to remove this after the tests have run?

I’m using version 1.11.0 of the runner as our gitlab is pretty old (so the after_script option doesn’t seem viable) and running a simple attempt to clean up after the test phase is throwing errors.

My gitlab-ci.yml file looks as below:
[q]> cat …/…/.gitlab-ci.yml

variables:
CI_PROJECT_DIR: /tmp

buildJob:
stage: test
script: “sh nonDeployedTools/buildAndTest.sh”

cleanUp:
stage: clean
script:
- “echo pwd
- “echo whoami
- “cd …/…/…/…/…”
- “echo pwd
- “ls -ltr builds”
- “rm -rf builds”

stages:

  • test
  • clean

When I run the above, the second last step of clean shows the builds folder is there, but when I try to rm it in the next stage I can a No such file or directory error (for a subfolder in builds) - this causes the ci build to fail, and it then removes the builds folder.

However if I don’t attempt to remove the directory, the build passes and the build folder is left behind in my repo.

If you’ve any suggestions on how to run clean up properly, or to change the directory the build runs from so I don’t get a new directory within my git repo that’d be much appreciated.

Thanks,
Nick