-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJenkinsfile
142 lines (130 loc) ยท 6.18 KB
/
Jenkinsfile
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
pipeline {
agent any
environment {
imagename = "lmslmsms0616/teamchat_back_chat"
registryCredential = 'docker-hub'
dockerImage = ''
}
stages {
// git์์ repository clone
stage('Prepare') {
steps {
echo 'Clonning Repository'
git url: 'https://github.com/KA-ForCloud/backend-chatting.git',
branch: 'master',
credentialsId: 'github_cred'
}
post {
success {
echo 'Successfully Cloned Repository'
}
failure {
error 'This pipeline stops here...'
}
}
}
// gradle build
stage('Bulid Gradle') {
agent any
steps {
echo 'Bulid Gradle'
dir ('.'){
sh """
./gradlew clean build --exclude-task test
"""
}
}
post {
failure {
error 'This pipeline stops here...'
}
}
}
// docker build
stage('Bulid Docker') {
agent any
steps {
echo 'Bulid Docker'
script {
dockerImage = docker.build imagename
}
}
post {
failure {
error 'This pipeline stops here...'
}
}
}
// docker push
stage('Push Docker') {
agent any
steps {
echo 'Push Docker'
script {
docker.withRegistry( '', registryCredential) {
dockerImage.push("${currentBuild.number}") // ex) "1.0"
}
}
}
post {
failure {
error 'This pipeline stops here...'
}
}
}
stage('Remove image in Jenkins'){
steps{
sh "docker rmi lmslmsms0616/teamchat_back_chat:${currentBuild.number}"
}
}
stage('Deploy to dev') {
steps {
sshagent(credentials: ['kic_key']) {
echo "sshagent start"
sh "ssh -o StrictHostKeyChecking=no [email protected] uptime"
echo "uptime end"
// sh "ssh -o StrictHostKeyChecking=no [email protected] -p 10003 'sudo chmod 666 /var/run/docker.sock'"
sh "ssh -o StrictHostKeyChecking=no [email protected] 'docker stop back_chat | true'"
sh "ssh -o StrictHostKeyChecking=no [email protected] 'docker rm back_chat | true'"
echo "docker remove"
sh "ssh -o StrictHostKeyChecking=no [email protected] 'docker rmi -f lmslmsms0616/teamchat_back_chat:latest | true'"
echo "docker remove image"
sh "ssh -o StrictHostKeyChecking=no [email protected] 'docker run -d --name back_chat -p 80:8081 -p 443:8081 -p 8081:8081 lmslmsms0616/teamchat_back_chat:${currentBuild.number}'"
echo "docker run"
//sh "ssh -o StrictHostKeyChecking=no [email protected] -p 10003 uptime"
//echo "uptime end"
// sh "ssh -o StrictHostKeyChecking=no [email protected] -p 10003 'sudo chmod 666 /var/run/docker.sock'"
//sh "ssh -o StrictHostKeyChecking=no [email protected] -p 10003 'docker stop back_chat | true'"
//sh "ssh -o StrictHostKeyChecking=no [email protected] -p 10003 'docker rm back_chat | true'"
//echo "docker remove"
//sh "ssh -o StrictHostKeyChecking=no [email protected] -p 10003 'docker rmi -f lmslmsms0616/teamchat_back_chat:latest | true'"
//echo "docker remove image"
//sh "ssh -o StrictHostKeyChecking=no [email protected] -p 10003 'docker run -d --name back_chat -p 80:8081 -p 443:8081 -p 8081:8081 lmslmsms0616/teamchat_back_chat:${currentBuild.number}'"
//echo "docker run"
//slackSend (channel: '#jenkins-alert', color: '#FFFF00', message: "WAS-1-BACKEND-CHAT Deploy Complete: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL})")
//echo "WAS_1_Success"
//sh "ssh -o StrictHostKeyChecking=no [email protected] -p 10004 uptime"
//echo "uptime end"
// sh "ssh -o StrictHostKeyChecking=no [email protected] -p 10004 'sudo chmod 666 /var/run/docker.sock'"
//sh "ssh -o StrictHostKeyChecking=no [email protected] -p 10004 'docker stop back_chat | true'"
//sh "ssh -o StrictHostKeyChecking=no [email protected] -p 10004 'docker rm back_chat | true'"
//echo "docker remove"
//sh "ssh -o StrictHostKeyChecking=no [email protected] -p 10004 'docker rmi -f lmslmsms0616/teamchat_back_chat:latest | true'"
//echo "docker remove image"
//sh "ssh -o StrictHostKeyChecking=no [email protected] -p 10004 'docker run -d --name back_chat -p 80:8081 -p 443:8081 -p 8081:8081 lmslmsms0616/teamchat_back_chat:${currentBuild.number}'"
//echo "docker run"
//slackSend (channel: '#jenkins-alert', color: '#FFFF00', message: "WAS-2-BACKEND-CHAT Deploy Complete: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL})")
//echo "WAS_2_Success"
}
}
post {
failure {
echo 'Update ์คํจใ
ใ
'
}
success {
echo 'Update ์ฑ๊ณต!!!! test'
}
}
}
}
}