How to enable maven artifact caching for gitlab ci runner?

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

    The accepted answer didn't do it for me.

    As zlobster mentioned, the guys at GitLab have this amazing repository where you can find a proper example of the .gitlab-ci.yml file used for Maven projects.

    Basically, what you need are these lines:

    cache:
      paths:
        - .m2/repository
    

    Keep in mind that if you decide to a add a local cache for a certain job, the global one added above will be replaced. More on this here.

    0 讨论(0)
  • 2020-12-12 17:54

    You can add cache folder to gitlab-ci runner configuration and pass it to maven.

    /etc/gitlab-runner/config.toml

    [[runners]]
    ...
      [runners.docker]
      ...
       volumes = ["/cache", "/.m2"]
      ...
    

    .gitlab-ci.yml

    variables:
      MAVEN_OPTS: "-Dmaven.repo.local=/.m2"
    
    build:
      script:
        - mvn package
    
    0 讨论(0)
提交回复
热议问题