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?
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.
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.
The artifacts are stored by default in /home/git/gitlab/shared/artifacts . Save the file and restart GitLab for the changes to take effect.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With