Unable to cache .m2 from Security/SAST.gitlab-ci.yml
Summary
The .m2/repository is not able to be cached when using the Security/SAST.gitlab-ci.yml
template. MAVEN_OPTS
contains -Dmaven.repo.local=$CI_PROJECT_DIR/.m2/repository
(from the maven template), and cache.path
is configured with .m2/repository
(also from the maven template). It caches fine for a standard maven build, but spotbugs-sast
says WARNING: .m2/repository: no matching files
Steps to reproduce
Create a Java 11 maven project with a gitlab-cy.yml file containing
# Run Gitlabs built in SAST template
include:
- template: Security/SAST.gitlab-ci.yml
variables:
SAST_JAVA_VERSION: 11
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"
default:
cache:
key: ${CI_JOB_NAME}
paths:
- .m2/repository
Example Project
None available
What is the current bug behavior?
If you add the following into the .gitlab-ci.yml file, you can see that the .m2
directory is missing at the point the project attempts to create the cache.
spotbugs-sast:
after_script:
- "ls -alrt"
$ ls -alrt
total 56
<...> 30 Apr 20 15:57 src
<...> 107 Apr 20 15:57 renovate.json
<...> 6608 Apr 20 15:57 mvnw.cmd
<...> 129 Apr 20 15:57 Dockerfile
<...> 21 Apr 20 15:57 .mvn
<...> 395 Apr 20 15:57 .gitignore
<...> 326 Apr 21 08:44 README.md
<...> 42 Apr 21 09:48 lombok.config
<...> 82 Apr 21 14:24 .gitlab-ci.yml
<...> 6512 Apr 22 09:52 pom.xml
<...> 168 Apr 30 09:11 ..
<...> 10070 Apr 30 11:51 mvnw
<...> 128 Apr 30 11:51 .git
<...> 298 Apr 30 11:52 target
<...> 1577 Apr 30 11:53 gl-sast-report.json
<...> 242 Apr 30 11:53 .
Saving cache for successful job
00:01
Creating cache spotbugs-sast...
WARNING: .m2/repository: no matching files
What is the expected correct behavior?
Should be able to cache the .m2
dir
Relevant logs and/or screenshots
see above
Output of checks
Results of GitLab environment info
Using gitlab-runner 13.10
Results of GitLab application Check
Possible fixes
Edited by Richard Ward