forked from pcmin929/fast-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
94 lines (88 loc) · 3.3 KB
/
Jenkinsfile
File metadata and controls
94 lines (88 loc) · 3.3 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
pipeline {
agent any
environment {
GITNAME = 'ksh0811'
GITEMAIL = 'iwcksh@gmail.com'
GITWEBADD = 'https://github.com/ksh0811/fast-code.git'
GITSSHADD = 'git@github.com:ksh0811/deployment.git'
GITCREDENTIAL = 'git_cre'
DOCKERHUB = 'ksh0811/fast'
DOCKERHUBCREDENTIAL = 'docker_cre'
}
stages {
stage('Checkout Github') {
steps {
checkout([$class: 'GitSCM', branches: [[name: '*/main']], extensions: [],
userRemoteConfigs: [[credentialsId: GITCREDENTIAL, url: GITWEBADD]]])
}
post {
failure {
sh "echo clone failed"
}
success {
sh "echo clone success"
}
}
}
stage('docker image build') {
steps {
sh "docker build -t ${DOCKERHUB}:${currentBuild.number} ."
sh "docker build -t ${DOCKERHUB}:latest ."
// currentBuild.number 젠킨스가 제공하는 빌드넘버 변수
// oolralra/fast:<빌드넘버> 와 같은 이미지가 만들어질 예정.
}
post {
failure {
sh "echo image build failed"
}
success {
sh "echo image build success"
}
}
}
stage('docker image push') {
steps {
withDockerRegistry(credentialsId: DOCKERHUBCREDENTIAL, url: '') {
sh "docker push ${DOCKERHUB}:${currentBuild.number}"
sh "docker push ${DOCKERHUB}:latest"
}
}
post {
failure {
sh "docker image rm -f ${DOCKERHUB}:${currentBuild.number}"
sh "docker image rm -f ${DOCKERHUB}:latest"
sh "echo push failed"
// 성공하든 실패하든 로컬에 있는 도커이미지는 삭제
}
success {
sh "docker image rm -f ${DOCKERHUB}:${currentBuild.number}"
sh "docker image rm -f ${DOCKERHUB}:latest"
sh "echo push success"
// 성공하든 실패하든 로컬에 있는 도커이미지는 삭제
}
}
}
stage('EKS manifest file update') {
steps {
git credentialsId: GITCREDENTIAL, url: GITSSHADD, branch: 'main'
sh "git config --global user.email ${GITEMAIL}"
sh "git config --global user.name ${GITNAME}"
sh "sed -i 's@${DOCKERHUB}:.*@${DOCKERHUB}:${currentBuild.number}@g' fast.yml"
sh "git add ."
sh "git branch -M main"
sh "git commit -m 'fixed tag ${currentBuild.number}'"
sh "git remote remove origin"
sh "git remote add origin ${GITSSHADD}"
sh "git push origin main"
}
post {
failure {
sh "echo manifest update failed"
}
success {
sh "echo manifest update success"
}
}
}
}
}