How to clean up gitlab-runner builds in Gitlab CI

Hello, I am learning to setup a CI pipeline in Gitlab (v12.3.5) using Gitlab-runner. It is working OK so far, but I notice the builds directory is filling up quite fast. My current .gitlab-ci.yaml file looks like this:

What would be an ideal way to cleanup the build directories so I don’t run out disk space. I did some searches and it seems like one solution is this: https://gitlab.com/snippets/1729438. But it involves setting up a cron job. The post looks over a year old. So I am wondering if there is a better (built-in?) way? Thank you.

# Change pip's cache directory to be inside the project directory since we can only cache local items.
variables:
  PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"

cache:
  paths:
    - .cache/pip
    - venv/
    - .tox

# Setup.
before_script:
  - export PATH=/nfs/pdx/disks/mpe_tvpv_002/sw_tools/anaconda3/bin:${PATH}
  - unset PYTHONHOME          # Make sure this is unset.
  - unset PYTHONPATH          # Make sure this is unset.
  - python --version          # NOTE: For debugging, do not remove.
  - virtualenv venv  
  - source venv/bin/activate  # Switch to local package environment.
  - pip install tox

# Pipeline stages.
stages:
  - build
  - quality
  - test
  - deploy

# Build and check the source distribution.
check:
  stage: build
  script:
    - cd python; tox -e check

# Run quality.
flake8:
  stage: quality
  script:
    - cd python; tox -e flake8

pylint:
  stage: quality
  script:
    - cd python; tox -e pylint

py_sort_imports:
  stage: quality
  script:
    - cd python; tox -e py_sort_imports

# Run unit tests.
unit_tests:
  stage: test
  script:
    - cd python

# TODO: Setup the deploy stage

Hi,

the cronjob looks good enough, I would implement that. I’d suggest liking or commenting to https://gitlab.com/gitlab-org/gitlab-runner/issues/3103 to raise awareness for this feature request :slight_smile:

Cheers,
Michael