-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
58 lines (52 loc) · 2.43 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
stages:
- build
- verify
- deploy
variables:
JAVA_HOME: "/opt/openjdk17" # Sets Java version to run (see /opt for details)
# 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 -P internal"
#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: '$GITLAB_USER_LOGIN != $RUNNER_USER_LOGIN && $CI_COMMIT_BRANCH && $CI_PIPELINE_SOURCE == "push"'
when: always
# if the first statement fails, never succeed
- when: never
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 deploy:
stage: deploy
script:
# --- 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
- mvn $MAVEN_CLI_OPTS -DskipTests clean deploy
rules:
- if: '$GITLAB_USER_LOGIN != $RUNNER_USER_LOGIN && $CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH && $CI_PIPELINE_SOURCE == "push"'
when: manual
- if: '$GITLAB_USER_LOGIN != $RUNNER_USER_LOGIN && $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $CI_PIPELINE_SOURCE == "push"'
when: manual