Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clear the workspace in gitlab in .gitlab-ci.yml?

When you create a job in jenkins, to clean up the workspace before build you can select under Build Environment the box that says Delete workspace before build starts.

How can you do the same when you run a job with gitlab? What line(s) must be added to the file .gitlab-ci.yml?

like image 562
Alex Avatar asked Sep 02 '25 16:09

Alex


1 Answers

By default you shouldn't need to do this, as GitLab has this configured under GITLAB_CLEAN_FLAGS which defaults to run git clean -ffdx before every job.

GitLab Runner configuration.


If you really want to make sure there is a clean environment, you can also use GIT_STRATEGY: clone (default is fetch).

clone is the slowest option. It clones the repository from scratch for every job, ensuring that the local working copy is always pristine. If an existing worktree is found, it is removed before cloning.

Git strategy configuration.

like image 111
Rekovni Avatar answered Sep 05 '25 14:09

Rekovni



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!