I'm trying to use Gitlab to create an automatic build for my Spring project. I've installed Docker on my local machine and setup Gitlab with a runner (the runner is not inside docker, I installed as regular windows service).
According to this configuration found on this stackoverflow thread I'm able to cache the .m2
folder to store all the downloaded dependencies.
Now, looking at Gitlab documentation I see that I can tag my cache that will be used across different branches. The same branch should use always the same cache to speed up the build process.
Now I tried to implement the pipeline and all is fine. But if I clear the cache and re-run the pipeline, the cache is used anyway, also if I cleared it (using the interface button).
This is the log of the pipeline:
Removing "..\\..\\..\\cache\\root\\core-library\\master-12\\cache.zip"
Removing .m2/
Removing target/
Skipping Git submodules setup
Restoring cache
Checking cache for master-13...
No URL provided, cache will not be downloaded from shared cache server. Instead a local version of cache will be extracted.
Successfully extracted cache
If i clear the cache, the next log increase the cache number (in this case become master-14
) but the cache is used anyway.. also if is the first run.
This is my simple pipeline, can someone help me to understand why the cache is used also if i forced the deletion ?
Pipeline example:
image: maven:3.6.3-openjdk-11
variables:
MAVEN_OPTS: "-Dhttps.protocols=TLSv1.2 -Dmaven.repo.local=$CI_PROJECT_DIR/.m2/repository -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=WARN -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:
key: ${CI_COMMIT_REF_SLUG}
paths:
- .m2/repository
build-job:
stage: build
script:
- echo "Cache key is $CI_COMMIT_REF_SLUG"
- mvn $MAVEN_CLI_OPTS -DskipTests install