1

I have spent an ample lot of time on this, and it doesn't seem to work. Have tried on multiple projects.

We host our gitlab runner ourselves (on our AWS via EKS) managed by Gitlab (SaaS). I want it to cache the maven dependencies.

When I configure it based on the reference example: https://gitlab.com/gitlab-org/gitlab-ci-yml/blob/master/Maven.gitlab-ci.yml , it still downloads all the dependencies every time.

stages:
  - test
  - pack

image: maven:3.6.1-jdk-8

variables:
  MAVEN_OPTS: "-Dhttps.protocols=TLSv1.2 -Dmaven.repo.local=$CI_PROJECT_DIR/.m2/repository -Dorg.slf4j.simpleLogger.showDateTime=true -Djava.awt.headless=true"
  MAVEN_CLI_OPTS: "--batch-mode --errors --fail-at-end --show-version -DinstallAtEnd=true -DdeployAtEnd=true"


cache:
  paths:
    - .m2/repository


stylecheck_and_test:
  stage: test
  only:
    - tags
    - schedulers
    - web
    - triggers
    - branches
  script:
    - mvn $MAVEN_CLI_OPTS install -Dmaven.test.skip=true
    - mvn $MAVEN_CLI_OPTS clean test
Jatin
  • 31,116
  • 15
  • 98
  • 163
  • Do you want caching between jobs / pipelines / branches / projects? – Jakob Liskow Jan 08 '21 at 23:04
  • Anything. I just want to make it work. Branches is fine – Jatin Jan 09 '21 at 03:04
  • This Gitlab-Doc (https://docs.gitlab.com/ee/ci/caching/) could help you. – Jakob Liskow Jan 12 '21 at 09:25
  • Tried it. Doesn't work. – Jatin Jan 12 '21 at 10:53
  • can you please post logs of your job, ideally you should see below logs when caching works fine `Checking cache for default... Downloading cache.zip from https://storage.googleapis.com/gitlab-com-runners-cache/project/****/default Successfully extracted cache .... .... .... .... Creating cache default... .m2/repository: found 2251 matching files and directories Uploading cache.zip to https://storage.googleapis.com/gitlab-com-runners-cache/project/****/default Created cache ` – Chintan Radia Jan 17 '21 at 09:49

2 Answers2

0

maybe you just faile the ci script so the cache was not created.

clf
  • 554
  • 6
  • 4
-1

Looks like local repo and cache paths are mismatch, Try with this.

stages:
  - test
  - pack

image: maven:3.6.1-jdk-8    

variables:
      MAVEN_OPTS: "-Dhttps.protocols=TLSv1.2 -Dmaven.repo.local=maven.repository -Dorg.slf4j.simpleLogger.showDateTime=true -Djava.awt.headless=true"
      MAVEN_CLI_OPTS: "--batch-mode --errors --fail-at-end --show-version -DinstallAtEnd=true -DdeployAtEnd=true"
    
    
    cache:
      paths:
        - maven.repository/

stylecheck_and_test:
  stage: test
  only:
    - tags
    - schedulers
    - web
    - triggers
    - branches
  script:
    - mvn $MAVEN_CLI_OPTS install -Dmaven.test.skip=true
    - mvn $MAVEN_CLI_OPTS clean test
Ravi Yadav
  • 57
  • 4