How to enable maven artifact caching for gitlab ci runner?

helt picture helt · Jun 13, 2016 · Viewed 37.9k times · Source

We use gitlab ci with shared runners to do our continuous integration. For each build, the runner downloads tons of maven artifacts.

Is there a way to configure gitlab ci to cache those artifacts so we can speed up the building process by preventing downloading the same artifact over and over again?

Answer

andban picture andban · Oct 13, 2016

Gitlab CI allows you to define certain paths, which contain data that should be cached between builds, on a per job or build basis (see here for more details). In combination with khmarbaise's recommendation, this can be used to cache dependencies between multiple builds.

An example that caches all job dependencies in your build:

cache:
  paths:
    - .m2/repository

variables:
  MAVEN_OPTS: "-Dmaven.repo.local=$CI_PROJECT_DIR/.m2/repository"

maven_job:
  script:
    - mvn clean install