-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
56 lines (49 loc) · 1.32 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
stages:
- build
- deploy
build:
stage: build
image:
name: maven:3.8.2-openjdk-17
pull_policy: if-not-present
before_script:
- echo "setting environment.."
script:
- echo "Compiling the code.."
- cd Eventi
- mvn clean install
- echo "Done compiling."
# -DskipTests
artifacts:
paths:
- Eventi/target/*.jar
deploy:
image:
name: alpine
pull_policy: if-not-present
stage: deploy
before_script:
- echo "Setting environment..."
- apk add sshpass
- apk add openssh-client
- eval $(ssh-agent -s)
- ssh-keygen -b 2048 -t rsa -f /root/.ssh/id_rsa -q -N ""
- sshpass -p $SSH_PASSWORD ssh -o StrictHostKeyChecking=no $SSH_USER@$MACHINE_IP ls
- sshpass -p $SSH_PASSWORD ssh-copy-id $SSH_USER@$MACHINE_IP
script:
- echo "Deploying application..."
- scp Eventi/target/*.jar $SSH_USER@$MACHINE_IP:/home/$SSH_USER/EVENTI_BACKEND.jar
- echo $(ssh $SSH_USER@$MACHINE_IP 'killall java')
# - ssh $SSH_USER@$MACHINE_IP 'rm out.log'
- ssh $SSH_USER@$MACHINE_IP 'nohup java -jar EVENTI_BACKEND.jar > out.log 2>&1 &'
- echo "Application successfully deployed."
#upload:
# image:
# name: curlimages/curl:latest
# pull_policy: if-not-present
# stage: deploy
# script:
# - 'curl -k'
workflow:
rules:
- if: $CI_COMMIT_BRANCH == 'main'