-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathJenkinsfile
More file actions
142 lines (125 loc) · 3.35 KB
/
Jenkinsfile
File metadata and controls
142 lines (125 loc) · 3.35 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
podTemplate(yaml: """
apiVersion: v1
kind: Pod
metadata:
labels:
jenkins/kaniko: "true"
spec:
nodeSelector:
jenkins-node: "true"
tolerations:
- key: "dedicated"
operator: "Equal"
value: "cicd"
effect: "NoSchedule"
containers:
- name: kaniko
image: gcr.io/kaniko-project/executor:v1.6.0-debug
imagePullPolicy: Always
command:
- /busybox/sh
args:
- -c
- sleep 99d # 그냥 살아만 있게
tty: true
volumeMounts:
- name: docker-config
mountPath: /kaniko/.docker # DockerHub 인증
- name: kaniko-build
mountPath: /workspace # build context
- name: kaniko-tmp
mountPath: /tmp
resources:
requests:
cpu: "500m"
memory: "1Gi"
volumes:
- name: docker-config
secret:
secretName: docker-config-dockerhub
items:
- key: .dockerconfigjson
path: config.json
- name: kaniko-build
persistentVolumeClaim:
claimName: pvc-kaniko-build-60
- name: kaniko-tmp
persistentVolumeClaim:
claimName: pvc-kaniko-tmp-30
""") {
node(POD_LABEL) {
stage('Checkout') {
// Webhook으로 받은 SCM 정보로 자동 checkout
checkout scm
}
stage('Copy to Kaniko Context') {
container('kaniko') {
sh """
rm -rf /workspace/*
cp -r ${WORKSPACE}/* /workspace/
"""
}
}
stage('SonarQube Analysis') {
withSonarQubeEnv('sonarQube') {
withCredentials([string(credentialsId: 'sonarQubeToken', variable: 'SONAR_TOKEN')]) {
sh """
./gradlew sonarqube \
-Dsonar.projectKey=backend \
-Dsonar.host.url=$SONAR_HOST_URL \
-Dsonar.login=$SONAR_TOKEN
"""
}
}
}
stage('Build & Push with Kaniko') {
container('kaniko') {
script {
def IMAGE = "docker.io/dockdock150/backend:${BUILD_NUMBER}"
// 빌드 및 DockerHub 푸시
sh """
/kaniko/executor \
--context /workspace \
--dockerfile /workspace/Dockerfile \
--destination ${IMAGE} \
--cache=true \
--cache-repo=docker.io/dockdock150/backend-cache \
--cleanup \
--force
"""
}
}
}
stage('Update Kustomize for ArgoCD') {
withCredentials([usernamePassword(credentialsId: 'git-clone', usernameVariable: 'GIT_USER', passwordVariable: 'GIT_PASS')]) {
script {
// ✅ Git 설정
sh '''
git config --global user.email "jenkins@ci.com"
git config --global user.name "Jenkins CI"
'''
// ✅ Deployment repo clone
sh '''
rm -rf DeploymentRepo
git clone https://$GIT_USER:$GIT_PASS@github.com/AllStackProject/Deployment.git DeploymentRepo
'''
// ✅ kustomization.yaml 수정
sh """
cd DeploymentRepo/backend/overlays/dev
sed -i 's|newTag:.*|newTag: "${BUILD_NUMBER}"|' kustomization.yaml
"""
// ✅ 변경사항 커밋 및 푸시
sh '''
cd DeploymentRepo
git add backend/overlays/dev/kustomization.yaml
git commit -m "chore: update image tag to ${BUILD_NUMBER}"
git push origin main
'''
}
}
}
stage('Post-Build') {
echo "✅ Docker image pushed to DockerHub successfully!"
}
}
}