How to enable maven artifact caching for gitlab ci runner?

后端 未结 8 1924
星月不相逢
星月不相逢 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:40

    If you are using kubernetes as executor for gitlab-runner, you can also use the maven cache. I chose to have a persistent cache on NFS with k8s PV (but other volume type are supported by gitlab-runner). The following configuration doesn't use the cache gitlab feature because of persistence offered by NFS.

    1) create a PersistentVolume on your cluster, ex here with NFS (adapt to your persistence layer and your options) :

    apiVersion: v1
    kind: PersistentVolume
    metadata:
      name: gitlabrunner-nfs-volume
    spec:
      capacity:
        storage: 10Gi
      mountOptions:
        - nolock
      accessModes:
        - ReadWriteMany
      persistentVolumeReclaimPolicy: Recycle
      nfs:
        path: /gitlabrunner
        server: 1.2.3.4
    

    2) Reference the PV to get a claim as a volume in the runner pod :

    [[runners.kubernetes.volumes.pvc]]
      name = "pvc-1"
      mount_path = "/path/to/mount/point1"
    

    Note (03/09/18) : A command line option for these paramaters doesn't exist yet. There is a open issue.

    3) Specify the same path for the gitlab-runner cache :

    [[runners]]
      executor = "kubernetes"
      # ...
      cache_dir = "/path/to/mount/point1"
    

    or

    --cache-dir "/path/to/mount/point1" in interactive mode

    4) use the "/path/to/mount/point1" directory in the -Dmaven.repo.local option

提交回复
热议问题