Clean only at beginning of pipeline but not between jobs


I would like to know if it is possible to only run git clean at the beginning of my CI pipeline but not between jobs of the same pipeline ?

I am using GitLab Community Edition version 14.8.2 on a self-hosted instance. Here is my setup (which explains my question), I have one single runner (version 14.10.0) to run my CI pipelines (so all jobs will be run on the same machine), hosted on a server with access to the Internet (so that it can communicate with the gitlab server hosted somewhere else). In addition, the runner is not actually doing the work but dispatches the computations to a local worker (which is a server without Internet access but with larger computing capability, required for my CI runs).

In my pipeline, I have different jobs, one configuring a local python environment, one compiling a software and one using this software and the python environment to run tests. So I would like for my jobs to share some files (environment setup, build products).

I know I can use the artifact setup (which is totally designed to handle this) but since I have only one runner, I would like to avoid useless data transfer on the network (since the files are produced and used on the same machine during a pipeline run).

To avoid the destruction of untracked files at the beginning of each job, I use the following in my .gitlab-ci.yml:


combined with a pre. jobs doing:

  stage: .pre
    - git clean -ffdx
    ## setup environment
    ## ...

to clean the repos at the beginning of the pipeline (for a fresh start).

Is there a better way to do what I want ? (without having to run the git clean command manually)

Hi there,

Maybe I’m missing something, but is there a reason not to say:

    GIT_CLEAN_FLAGS: "-ffdx"

And remove the before_script?

@snim2 Yes, if I do that, git clean -ffdx will be run at the beginning of each job (that is the default behavior, equivalent to not defining the GIT_CLEAN_FLAGS variable), and my environment files and build product files will be removed between jobs (and I want them to be kept between jobs in the same pipeline run, except for the 1st job at the beginning of the pipeline).

Ah, I see what you mean.

TBH I don’t think there’s a better way than what you already have.

The only other thing that springs to mind is to turn off Git clone entirely, by setting:


at the top of your file, and running clone etc. on a per-job basis.