-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile.template
107 lines (76 loc) · 2.92 KB
/
Jenkinsfile.template
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
pipeline {
agent any
stages {
stage('Check Connection') {
steps {
script{
sshagent(['79a4420b-3683-4745-a8a1-9e27b796f7b3']) {
sh '''
ssh alamin@45.120.115.246 "echo "server running....""
'''
}
}
}
post {
success {
notifyDiscord("Connection success!")
}
failure {
notifyDiscord("Connection failed!")
}
}
}
stage('update code') {
steps {
script{
sshagent(['79a4420b-3683-4745-a8a1-9e27b796f7b3']) {
sh '''
ssh alamin@45.120.115.246 "
cd /home/alamin/storage/dcl-project/{{APP_NAME}} &&
sudo git reset . &&
sudo git clean -df &&
sudo git stash &&
sudo git pull
"
'''
}
}
}
post {
success {
notifyDiscord("update code success!")
}
failure {
notifyDiscord("update code failed!")
}
}
}
stage('deploy code') {
steps {
script{
sshagent(['79a4420b-3683-4745-a8a1-9e27b796f7b3']) {
sh '''
ssh alamin@45.120.115.246 "
cd /home/alamin/storage/dcl-project/{{APP_NAME}} &&
sudo docker compose up -d --build &&
sudo docker system prune -af
"
'''
}
}
}
post {
success {
notifyDiscord("deploy success!")
}
failure {
notifyDiscord("deploy failed!")
}
}
}
}
}
def notifyDiscord(message) {
def discordWebhookUrl = 'https://discord.com/api/webhooks/1145653952562597918/b9wR-EbUYiBOOsn3jHGxq1Cg45sGiz45yfo_ASMtAXZzMmhpyvvzQCEl7EL-OBrwUXgS'
sh "curl -X POST -H 'Content-Type: application/json' -d '{\"content\":\"${message}\"}' ${discordWebhookUrl}"
}