-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
155 lines (143 loc) Β· 3.84 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# You can override the included template(s) by including variable overrides
# SAST customization: https://docs.gitlab.com/ee/user/application_security/sast/#customizing-the-sast-settings
# Secret Detection customization: https://docs.gitlab.com/ee/user/application_security/secret_detection/#customizing-settings
# Dependency Scanning customization: https://docs.gitlab.com/ee/user/application_security/dependency_scanning/#customizing-the-dependency-scanning-settings
# Container Scanning customization: https://docs.gitlab.com/ee/user/application_security/container_scanning/#customizing-the-container-scanning-settings
# Note that environment variables can be set in several places
# See https://docs.gitlab.com/ee/ci/variables/#cicd-variable-precedence
image: gradle:alpine
stages:
- build
- code-quality
- deploy
- update
before_script:
- export GRADLE_USER_HOME=`pwd`/.gradle
- chmod +x $CI_PROJECT_DIR/gradlew
build:
stage: build
only:
- /^develop$/i
- /^main$/i
- /^release.*$/i
- merge_requests
script:
- echo "π’ Compiling the code ..."
- $CI_PROJECT_DIR/gradlew --build-cache assemble
- echo "Compile complete."
artifacts:
name: "${CI_JOB_NAME}-${CI_COMMIT_REF_SLUG}"
untracked: true
expire_in: 1 hour
tags:
- education
unit-test:
stage: code-quality
needs:
- job: build
artifacts: true
only:
- /^develop$/i
- /^main$/i
- /^release.*$/i
- merge_requests
script:
- echo "π Running unit tests ..."
- $CI_PROJECT_DIR/gradlew test jacocoTestReport
- echo "π Unit tests complete."
artifacts:
when: always
reports:
junit: build/test-results/test/**/TEST-*.xml
paths:
- $CI_PROJECT_DIR/build/reports/jacoco/test/jacocoTestReport.xml
tags:
- education
coverage:
stage: code-quality
needs:
- job: unit-test
artifacts: true
only:
- /^develop$/i
- /^main$/i
- /^release.*$/i
- merge_requests
image: registry.gitlab.com/haynes/jacoco2cobertura:1.0.7
script:
- python /opt/cover2cover.py build/reports/jacoco/test/jacocoTestReport.xml $CI_PROJECT_DIR/src/main/java/ > build/cobertura.xml
artifacts:
reports:
coverage_report:
coverage_format: cobertura
path: build/cobertura.xml
tags:
- education
sonarqube-check:
stage: code-quality
needs:
- job: build
artifacts: true
- job: unit-test
artifacts: true
- job: coverage
artifacts: true
variables:
SONAR_USER_HOME: "${CI_PROJECT_DIR}/.sonar"
GIT_DEPTH: "0"
cache:
key: "${CI_JOB_NAME}"
paths:
- .sonar/cache
script: gradle sonar
allow_failure: true
only:
- merge_requests
- main
- develop
tags:
- education
sast:
stage: code-quality
tags:
- education
docker-job:
stage: deploy
image: docker:latest # Use the official docker image.
services:
- docker:dind
variables:
IMAGE_TAG: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG
before_script:
- docker info
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- ls build/libs/
script:
- echo "π Starting docker build ..."
- docker build -t $IMAGE_TAG -f ./Dockerfile .
- echo "π€ Pushing image ..."
- docker push $IMAGE_TAG
- echo "π€ image pushed."
tags:
- education
watchtower-update:
stage: update
needs:
- job: docker-job
artifacts: true
variables:
CURL_UPDATE: 'curl -H "Authorization: Bearer =wU.603i3s97" http://namibia.sybit.de:8080/v1/update'
before_script:
- apk --no-cache --update add curl
script:
- echo "π‘ Watchtower starts Container update ..."
- 'eval "$CURL_UPDATE"'
- echo "Container got updated."
rules:
- if: $CI_COMMIT_BRANCH == "develop"
when: delayed
start_in: 5 minutes
tags:
- education
include:
- template: Security/SAST.gitlab-ci.yml