-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
117 lines (112 loc) · 3.92 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
pipeline{
agent {
kubernetes{
yaml '''
apiVersoin: v1
kind: Pod
spec:
serviceAccountName: jenkins
containers:
- name: yq
image: mikefarah/yq
tty : true
command:
- sleep
args:
- infinity
- name: aws
image: amazon/aws-cli
command:
- sleep
args:
- infinity
- name: gradle
image: gradle:8.1.1
command: ['sleep']
args: ['infinity']
- name: kaniko
image: gcr.io/kaniko-project/executor:debug
command:
- sleep
args:
- infinity
env:
- name: AWS_SDK_LOAD_CONFIG
value: true
'''
}
}
stages{
stage('Git Clone'){
steps{
git url: 'https://github.com/SWM-YouQuiz/User-Service.git',
branch: "${branch.split("/")[2]}",
credentialsId: "github_personal_access_token"
script{
def commitHash = sh(script: 'git rev-parse HEAD', returnStdout: true)
sh "echo ${commitHash}"
env.tag = commitHash
}
}
}
stage('Gradle Build'){
steps{
container('gradle'){
sh 'mkdir ./src/main/resources/static'
sh 'mkdir ./src/main/resources/static/docs'
sh 'gradle build'
sh 'mv ./build/libs/user-service.jar ./'
}
}
}
stage('aws'){
steps{
container('aws'){
sh "aws s3 cp src/main/resources/static/docs/api.yml s3://quizit-swagger/user.yml"
}
}
}
stage('Docker Build'){
steps{
container('kaniko'){
script{
sh "executor --dockerfile=Dockerfile --context=dir://${env.WORKSPACE} --destination=${env.ECR_USER_SERVICE}:${env.tag}"
}
}
}
post{
failure{
slackSend(color: '#FF0000', message: "FAIL : Docker 이미지 Push 실패 '${env.JOB_NAME} [${env.BUILD_NUMBER}]' tag: ${env.tag}")
}
success{
slackSend(color: '#0AC9FF', message: "SUCCESS : Docker 이미지 Push 성공 '${env.JOB_NAME} [${env.BUILD_NUMBER}]' tag: ${env.tag}")
}
}
}
stage('Git Manifest Edit & Push'){
steps{
container('yq'){
script {
dir('helm') {
git url: 'https://github.com/SWM-YouQuiz/Helm.git',
branch: 'dev',
credentialsId: "github_personal_access_token"
sh "yq e -i -P '.quizItService.user.image.tag = \"${env.tag}\"' values-dev.yaml"
}
}
}
script{
dir('helm'){
withCredentials([gitUsernamePassword(credentialsId: 'github_personal_access_token')]){
sh 'git config --global user.email "<>"'
sh 'git config --global user.name "Jenkins-User"'
sh "git add ."
sh "git commit -m '${env.tag}'"
sh 'git push origin dev'
}
}
}
}
}
}
}