-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJenkinsfile
159 lines (139 loc) ยท 6.6 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
// docker
pipeline {
agent any
environment{
imagename = "lmslmsms0616/teamchat_front"
registryCredential = 'docker-hub'
dockerImage = ''
}
stages {
// git์์ repository clone
stage('Prepare') {
steps {
echo 'Clonning Repository'
git url: 'https://github.com/KA-ForCloud/Frontend.git',
branch: 'master'
}
post {
success {
echo 'Successfully Cloned Repository'
}
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_front:${currentBuild.number}"
}
}
stage('Deploy to dev') {
steps {
sshagent(credentials: ['kic_key']) {
echo "sshagent start"
sh "ssh -o StrictHostKeyChecking=no [email protected] -p 10001 uptime"
echo "uptime end"
sh "ssh -o StrictHostKeyChecking=no [email protected] -p 10001 'sudo chmod 666 /var/run/docker.sock'"
sh "ssh -o StrictHostKeyChecking=no [email protected] -p 10001 'docker stop front | true'"
sh "ssh -o StrictHostKeyChecking=no [email protected] -p 10001 'docker rm front | true'"
echo "docker remove"
sh "ssh -o StrictHostKeyChecking=no [email protected] -p 10001 'docker rmi -f lmslmsms0616/teamchat_front:latest | true'"
echo "docker remove image"
sh "ssh -o StrictHostKeyChecking=no [email protected] -p 10001 'docker run -d --name front -p 80:80 -p 443:443 -p 3000:3000 lmslmsms0616/teamchat_front:${currentBuild.number}'"
echo "docker run"
slackSend (channel: '#jenkins-alert', color: '#FFFF00', message: "WEB-1-Frontend Deploy Complete: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL})")
echo "Web_1_Success"
sh "ssh -o StrictHostKeyChecking=no [email protected] -p 10002 uptime"
sh "ssh -o StrictHostKeyChecking=no [email protected] -p 10002 'sudo chmod 666 /var/run/docker.sock'"
sh "ssh -o StrictHostKeyChecking=no [email protected] -p 10002 'docker stop front | true'"
sh "ssh -o StrictHostKeyChecking=no [email protected] -p 10002 'docker rm front | true'"
sh "ssh -o StrictHostKeyChecking=no [email protected] -p 10002 'docker rmi -f lmslmsms0616/teamchat_front:latest | true'"
sh "ssh -o StrictHostKeyChecking=no [email protected] -p 10002 'docker run -d --name front -p 80:80 -p 443:443 -p 3000:3000 lmslmsms0616/teamchat_front:${currentBuild.number}'"
slackSend (channel: '#jenkins-alert', color: '#FFFF00', message: "WEB-2-Frontend Deploy Complete: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL})")
echo "Web_2_Success"
}
}
post {
failure {
echo 'Update ์คํจใ
ใ
'
}
success {
echo 'Update ์ฑ๊ณต!!!! test'
}
}
}
}
}
// npm
// node {
// checkout scm
// stage('build') {
// nvm(nvmInstallURL: 'https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh',
// nvmIoJsOrgMirror: 'https://iojs.org/dist',
// nvmNodeJsOrgMirror: 'https://nodejs.org/dist',
// version: '16.19.0') {
// sh "node -v"
// // sh "apt-get update"
// // sh "apt-get install gcc g++ make -y"
// sh "npm install --legacy-peer-deps"
// echo "Build main site distribution"
// sh "CI=false npm run build"
// slackSend (channel: '#jenkins-alert', color: '#FFFF00', message: "Frontend Build Complete: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL})")
// }
// }
// stage('Deploy') {
// echo "Deploy Start"
// sshagent(credentials: ['kic_key']) {
// echo "sshagent start"
// sh "ssh -o StrictHostKeyChecking=no [email protected] -p 10001 uptime"
// sh "scp -r -P 10001 /var/jenkins_home/workspace/forCloud_Frontend_Pipeline/build [email protected]:/home/centos/Frontend"
// echo "here"
// sh "ssh -T [email protected] -p 10001 'cd /home/centos/Frontend'"
// echo "here"
// sh "ssh -T [email protected] -p 10001 'npm start'"
// slackSend (channel: '#jenkins-alert', color: '#FFFF00', message: "WEB-1-Frontend Deploy Complete: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL})")
// echo "Web_1_Success"
// // sh '''
// // ssh -o StrictHostKeyChecking=no [email protected] -p 10002 uptime
// // ssh -T [email protected] -p 10002 ./please.sh
// // scp -r -P 10002 /var/jenkins_home/workspace/forCloud_Frontend_Pipeline/build [email protected]:/home/centos/Frontend
// // ssh -T [email protected] -p 10002 ./deploy.sh
// // '''
// // slackSend (channel: '#jenkins-alert', color: '#FFFF00', message: "WEB-2-Frontend Deploy Complete: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL})")
// // echo "Web_2_Success"
// }
// }
// }