-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
105 lines (95 loc) · 2.67 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
image: java:8-jdk
variables:
GIT_STRATEGY: clone
before_script:
- export GRADLE_USER_HOME='pwd'/.gradle
- chmod +x ./gradlew
cache:
paths:
- .gradle/wrapper --gradle-version=6.6.1 --distribution-type=bin
- .gradle/caches
stages:
- build
- build_prod
- test
- deploy
- deploy_prod
build:
image: gradle:alpine
stage: build
script:
- ./gradlew assemble
artifacts:
paths:
- build/libs/*.jar
tags:
- ugrad
only:
- develop
build_prod:
image: gradle:alpine
stage: build
script:
- ./gradlew assemble
artifacts:
paths:
- build/libs/*.jar
tags:
- ugrad
only:
- release
test:
stage: test
script:
- ./gradlew check
artifacts:
when: always
reports:
junit:
- build/surefire-reports/TEST-*.xml
tags:
- ugrad
only:
- release
deploy:
stage: deploy
image: gradle:alpine
before_script:
- 'command -v ssh-agent >/dev/null || ( apt-get update -y && apt-get install openssh-client -y )'
- eval $(ssh-agent -s)
- echo "$DEPLOY_SSH_KEY" | tr -d '\r' | ssh-add -
script:
- file="application.properties"
- echo "Driver=$DATABASE_DRIVER" > $file
- echo "Password=$DATABASE_PASSWORD_TEST" >> $file
- echo "Url=$DATABASE_URL_TEST" >> $file
- echo "Username=$DATABASE_USERNAME_TEST" >> $file
- cat $file
- zip -r ${CI_COMMIT_REF_NAME}_${CI_COMMIT_SHORT_SHA}.zip . -i /build/libs/*.jar
- scp -r -o StrictHostKeyChecking=no ${CI_COMMIT_REF_NAME}_${CI_COMMIT_SHORT_SHA}.zip "${DEPLOY_USER_TEST}@${DEPLOY_HOST}:${DEPLOY_DIR}/${CI_COMMIT_REF_NAME}_${CI_COMMIT_SHORT_SHA}.zip"
- scp -r -o StrictHostKeyChecking=no $file "${DEPLOY_USER_TEST}@${DEPLOY_HOST}:${DEPLOY_DIR}/${file}"
tags:
- ugrad
only:
- develop
deploy_prod:
stage: deploy
image: gradle:alpine
before_script:
- 'command -v ssh-agent >/dev/null || ( apt-get update -y && apt-get install openssh-client -y )'
- eval $(ssh-agent -s)
- echo "$DEPLOY_SSH_KEY_PROD" | tr -d '\r' | ssh-add -
script:
- file="application.properties"
- echo "Driver=$DATABASE_DRIVER" > $file
- echo "Password=$DATABASE_PASSWORD_PROD" >> $file
- echo "Url=$DATABASE_URL_PROD" >> $file
- echo "Username=$DATABASE_USERNAME_PROD" >> $file
- cat $file
- zip -r ${CI_COMMIT_REF_NAME}_${CI_COMMIT_SHORT_SHA}.zip . -i /build/libs/*.jar
- scp -r -o StrictHostKeyChecking=no ${CI_COMMIT_REF_NAME}_${CI_COMMIT_SHORT_SHA}.zip "${DEPLOY_USER_PROD}@${DEPLOY_HOST}:${DEPLOY_DIR}/${CI_COMMIT_REF_NAME}_${CI_COMMIT_SHORT_SHA}.zip"
- scp -r -o StrictHostKeyChecking=no $file "${DEPLOY_USER_PROD}@${DEPLOY_HOST}:${DEPLOY_DIR}/${file}"
tags:
- ugrad
only:
- release