3

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?

danielnelz
  • 3,794
  • 4
  • 25
  • 35
Alex
  • 41,580
  • 88
  • 260
  • 469

1 Answers1

1

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.

Rekovni
  • 6,319
  • 3
  • 39
  • 62
  • 2
    Be warned that cleaning the work directory get disabled when you disable the git checkout with `GIT_STRATEGY: none`. In my case I running a shell executor on some host to do the deployment which accumulates previous artifacts unless I explicitly clean them manually in the job. – pmhahn Sep 08 '22 at 13:50
  • I've done some research, and there is no option to solve this issue. Gitlab issue tracker contains lots of requests - also from paid customers - but decision is to do not introduce another strategy. As simple solution I've decided to restore `clone` in minimal range (shallow, no submodules, etc). – niziak Apr 05 '23 at 10:13