-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjenkins-pipeline-front.groovy
More file actions
175 lines (169 loc) · 7.02 KB
/
Copy pathjenkins-pipeline-front.groovy
File metadata and controls
175 lines (169 loc) · 7.02 KB
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
pipeline {
agent any
stages {
stage('Git Clone') {
steps {
script {
try {
git url: "https://github.com/KEAPoint/OnLog_Front", branch: "main", credentialsId: 'Bal1oon'
env.cloneResult=true
} catch (error) {
print(error)
env.cloneResult=false
currentBuild.result = 'FAILURE'
}
}
}
post {
success {
slackSend (
channel: '#jenkins-notification',
color: '#2C953C',
message: "=========================================\nPipeline Start: Job ${env.JOB_NAME} (${env.BUILD_NUMBER})"
)
}
}
}
stage('ECR Upload') {
steps{
script{
try {
sh 'aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin 629515838455.dkr.ecr.us-east-1.amazonaws.com'
sh "docker build -t kea-004-onlog-front:${env.BUILD_NUMBER} ."
sh "docker tag kea-004-onlog-front:${env.BUILD_NUMBER} 629515838455.dkr.ecr.us-east-1.amazonaws.com/kea-004-onlog-front:${env.BUILD_NUMBER}"
sh "docker tag kea-004-onlog-front:${env.BUILD_NUMBER} 629515838455.dkr.ecr.us-east-1.amazonaws.com/kea-004-onlog-front:latest"
sh "docker push 629515838455.dkr.ecr.us-east-1.amazonaws.com/kea-004-onlog-front:${env.BUILD_NUMBER}"
sh "docker push 629515838455.dkr.ecr.us-east-1.amazonaws.com/kea-004-onlog-front:latest"
} catch (error) {
print(error)
echo 'Remove Deploy Files'
sh "rm -rf /var/lib/jenkins/workspace/onlog-blog-ci-cd/*"
currentBuild.result = 'FAILURE'
}
}
}
post {
success {
echo "The ECR Upload stage successfully."
slackSend (
channel: '#jenkins-notification',
color: '#2C953C',
message: "Success: ECR Upload"
)
}
failure {
echo "The ECR Upload stage failed."
slackSend (
channel: '#jenkins-notification',
color: '#FF3232',
message: "Fail: ECR Upload"
)
}
}
}
stage('Git Clone KEAPoint/OnLog-k8s') {
steps {
script {
try {
git url: "https://github.com/KEAPoint/OnLog-k8s.git", branch: "main", credentialsId: 'Bal1oon'
env.cloneResult=true
} catch (error) {
print(error)
env.cloneResult=false
currentBuild.result = 'FAILURE'
}
}
}
post {
success {
slackSend (
channel: '#jenkins-notification',
color: '#2C953C',
message: "Success: Git Clone KEAPoint/OnLog-k8s"
)
}
failure {
slackSend (
channel: '#jenkins-notification',
color: '#FF3232',
message: "Fail: Git Clone KEAPoint/OnLog-k8s"
)
}
}
}
stage('Update Kubernetes Manifests') {
steps {
script {
sh "sed -i 's|kea-004-onlog-front:.*|kea-004-onlog-front:${env.BUILD_NUMBER}|' /var/jenkins_home/workspace/onlog-front-deploy/base/frontend/deployment/deploy-onlog-front.yaml"
}
}
post {
success {
slackSend (
channel: '#jenkins-notification',
color: '#2C953C',
message: "Success: Update Kubernetes Manifests"
)
}
failure {
slackSend (
channel: '#jenkins-notification',
color: '#FF3232',
message: "Fail :Update Kubernetes Manifests"
)
}
}
}
stage('Git Push') {
steps {
script {
withCredentials([usernamePassword(credentialsId: 'Bal1oon', passwordVariable: 'GIT_TOKEN', usernameVariable: 'GIT_USERNAME')]) {
try {
sh 'git config --global user.name "${GIT_USERNAME}"'
sh 'git config --global user.email "ws32159@naver.com"'
sh 'cd /var/jenkins_home/workspace/onlog-front-deploy/base && git add .'
sh "cd /var/jenkins_home/workspace/onlog-front-deploy/base && git commit -m \"Update onlog-front ver.${env.BUILD_NUMBER} from Jenkins pipeline\""
sh 'git remote set-url origin https://Bal1oon:$GIT_TOKEN@github.com/KEAPoint/OnLog-k8s.git'
sh 'cd /var/jenkins_home/workspace/onlog-front-deploy/base && git push origin main'
} catch (error) {
print(error)
currentBuild.result = 'FAILURE'
}
}
}
}
post {
success {
slackSend (
channel: '#jenkins-notification',
color: '#2C953C',
message: "Success: Git Push to K8S Manifest Repository"
)
}
failure {
slackSend (
channel: '#jenkins-notification',
color: '#FF3232',
message: "Fail: Git Push to K8S Manifest Repository"
)
}
}
}
}
post {
success {
slackSend (
channel: '#jenkins-notification',
color: '#2C953C',
message: "SUCCESS: Job ${env.JOB_NAME} (${env.BUILD_NUMBER})\n========================================="
)
}
failure {
slackSend (
channel: '#jenkins-notification',
color: '#FF3232',
message: "FAIL: Job ${env.JOB_NAME} (${env.BUILD_NUMBER})\n========================================="
)
}
}
}