- Tell java to use JaCoCo Agent while running the application inside the container
-javaagent:/home/java/jacoco.jar=destfile=folder_inside_contrainer/jacoco-it.exec,append=true
- Configure Agent to write the results into folder_inside_contrainer
replace *folder_inside_contrainer* with the one you will share with the host later on
- Share folder folder_inside_contrainer between the container and the host (in this case GitLab Job)
docker run -d -v gitlab_folder:folder_inside_contrainer
- Export results that are in .exec format into .html format via JaCoCo-cli.jar
java -jar jacococli.jar report gitlab_folder/jacoco-it.exec --classfiles path_to_app_compiled_classes --html coverage/api-coverage-html
- Grab the coverage from HTML and display it for that job
api-coverage:
stage: release
script:
- 'apt-get install -y unzip'
- 'curl -L "https://search.maven.org/remotecontent?filepath=org/jacoco/jacoco/0.8.6/jacoco-0.8.6.zip" -o jacoco.zip'
- 'unzip jacoco'
- 'java -jar lib/jacococli.jar report gitlab_folder/jacoco-it.exec --classfiles path_to_app_compiled_classes --html coverage/api-coverage-html'
- grep -oP "Total.*?([0-9]{1,3})%" coverage/api-coverage-html/index.html
coverage: "/Total.*?([0-9]{1,3})%/"
artifacts:
paths:
- coverage/
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…