Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable maven artifact caching for GitLab CI runner?

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?

like image 676
helt Avatar asked Jun 13 '16 08:06

helt


People also ask

How does Maven cache work?

Implementation insights. At very simple form, the build cache Maven is essentially a hash function which takes Maven project and produces cache key for a project. Then the key is used to store and restore build results. Because of different factors there could be collisions and instabilities in the produced key.

What is the difference between caching and artifacts GitLab?

Cache is stored where GitLab Runner is installed and uploaded to S3 if distributed cache is enabled. Use artifacts to pass intermediate build results between stages. Artifacts are generated by a job, stored in GitLab, and can be downloaded.

Where does GitLab runner store artifacts?

The artifacts are stored by default in /home/git/gitlab/shared/artifacts . Save the file and restart GitLab for the changes to take effect.


1 Answers

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 
like image 52
andban Avatar answered Oct 18 '22 05:10

andban