Skip to content

Instantly share code, notes, and snippets.

@combemale
Last active January 31, 2021 11:04
Show Gist options
  • Save combemale/fb68a577d91a6594594a145b162aeb9b to your computer and use it in GitHub Desktop.
Save combemale/fb68a577d91a6594594a145b162aeb9b to your computer and use it in GitHub Desktop.
Example of a simple .gitlab-ci.yml
java:
stage: test
script:
- mvn verify
artifacts:
when: always
reports:
junit:
- target/surefire-reports/TEST-*.xml
- target/failsafe-reports/TEST-*.xml
test-jdk11:
stage: test
image: maven:3.6.3-jdk-11
script:
- 'mvn $MAVEN_CLI_OPTS clean org.jacoco:jacoco-maven-plugin:prepare-agent test jacoco:report'
artifacts:
paths:
- target/site/jacoco/jacoco.xml
coverage-jdk11:
# Must be in a stage later than test-jdk11's stage.
# The `visualize` stage does not exist by default.
# Please define it first, or chose an existing stage like `deploy`.
stage: visualize
image: haynes/jacoco2cobertura:1.0.4
script:
# convert report from jacoco to cobertura
- 'python /opt/cover2cover.py target/site/jacoco/jacoco.xml src/main/java > target/site/cobertura.xml'
# read the <source></source> tag and prepend the path to every filename attribute
- 'python /opt/source2filename.py target/site/cobertura.xml'
needs: ["test-jdk11"]
dependencies:
- test-jdk11
artifacts:
reports:
cobertura: target/site/cobertura.xml
sonarqube-check:
image: maven:3.6.3-jdk-11
variables:
SONAR_USER_HOME: "${CI_PROJECT_DIR}/.sonar" # Defines the location of the analysis task cache
GIT_DEPTH: "0" # Tells git to fetch all the branches of the project, required by the analysis task
cache:
key: "${CI_JOB_NAME}"
paths:
- .sonar/cache
script:
- mvn verify sonar:sonar -Dsonar.qualitygate.wait=true
allow_failure: true
only:
- merge_requests
- master
- develop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment