How to enable maven artifact caching for gitlab ci runner?

后端 未结 8 1951
星月不相逢
星月不相逢 2020-12-12 17:14

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 gitl

8条回答
  •  鱼传尺愫
    2020-12-12 17:36

    There is another approach. Do not use gitlab cache and use custom (per project) docker image.

    Some details:

    First of all, you need to create a maven docker image where all (or most of) required for your project dependencies are presented. Publish it to your registry (gitlab has one) and use it for any job running maven.

    To create such an image I usually create an additional job in CI triggered manually. You need to trigger it at initial stage and when project dependencies are heavily modified.

    Working sample can be found here:

    https://gitlab.com/alexej.vlasov/syncer/blob/master/.gitlab-ci.yml - this project is using the prepared image and also it has a job to prepare this image.

    https://gitlab.com/alexej.vlasov/maven/blob/master/Dockerfile - dockerfile to run maven and download dependencies once.

    The pros:

    • don't need to download dependencies each time - they are inside a docker image (and docker layers are cached on the runners)
    • don't need to upload artifacts when job is finished
    • cache are not downloaded in jobs don't use maven

提交回复
热议问题