-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
73 lines (63 loc) · 2.97 KB
/
.gitlab-ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
stages:
- build
- verify
- document
- deploy
variables:
JAVA_HOME: "/usr/lib/jvm/java-17-openjdk-amd64" # Sets Java version to run (see /opt for details)
VERSION_COMMIT: "GitLab CI Versioning Commit" # Commit text for version update
VERSION_BRANCH: "update_version" # Branch used to merge version update commit
# Sets the artifact cache to a local directory within build area
MAVEN_CLI_OPTS: "-Dmaven.repo.local=.m2/repository --batch-mode -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=WARN"
#Workflow rules that filters across the entire pipeline. Cleaner than -o ci.skip since there won't be a "skipped" pipeline.
workflow:
rules:
# If user is not the runner, branch is the default branch, and the pipeline source is a push
- if: '$GITLAB_USER_LOGIN != $RUNNER_USER_LOGIN && $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $CI_PIPELINE_SOURCE == "push"'
when: always
# if the first statement fails, never succeed
- when: never
# Cache the artifact repository (not the target directory, as that causes old classes that are deleted to persist, and be deployed when they shouldn't be).
cache:
paths:
- .m2/repository/
maven build:
stage: build
script:
# --- Checks if code compiles
- mvn $MAVEN_CLI_OPTS clean compile
maven verify:
stage: verify
script:
# -fn indicates that it should never fail, this allows artifacts to be built even when unit tests fail to execute successfully
- mvn $MAVEN_CLI_OPTS clean verify
# instruct gitlab to capture the test reports
# test reporting to be handled in gitlab requires:
# sudo gitlab-rails console
# irb(main):001:0> Feature.enable(:junit_pipeline_view,Project.find(84))
artifacts:
reports:
junit:
- target/surefire-reports/TEST-*.xml
- target/failsafe-reports/TEST-*.xml
# Allows a this job to fail, and the pipeline will continue
allow_failure: true
maven document:
stage: document
script:
- mvn $MAVEN_CLI_OPTS clean -DadditionalJOption=-Xdoclint:none javadoc:aggregate-jar
maven deploy:
stage: deploy
script:
# --- set version to last commit date+hash
- UPDATED_VERSION=$(git log -1 --format=%cd --date=format:%Y.%m.%d)-$CI_COMMIT_SHORT_SHA
- echo updated deployment version to $UPDATED_VERSION
# --- Set the update version in the pom file(s)
- mvn $MAVEN_CLI_OPTS versions:set -q -DnewVersion=${UPDATED_VERSION}
# --- Deploy to artifactory
# Again, -fn might be necessary here if artifacts are to be deployed even when unit tests fail
# -DskipTests will not execute unit tests, this should allow the artifact to be deployed if unit tests fail in the previous stage
# -Dmaven.test.skip=true will also stop the unit tests from being compiled--which potentially would speed this up
# -Dmaven.javadoc.failOnError=false instructs this to proceed even if javadoc generation fails
- mvn $MAVEN_CLI_OPTS -DskipTests -Dmaven.javadoc.failOnError=false clean deploy
when: manual