forked from jwkwon-715/donimoney
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
72 lines (65 loc) · 1.83 KB
/
Jenkinsfile
File metadata and controls
72 lines (65 loc) · 1.83 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
def app
pipeline {
agent any
environment {
PROJECT_ID = 'resonant-sunset-466808-s8'
CLUSTER_NAME = 'kube'
LOCATION = 'asia-northeast3-a'
CREDENTIALS_ID = 'gke'
DOCKER_IMAGE = 'jinseon901/test'
}
stages {
stage('Checkout') {
steps {
checkout scm
}
}
stage('Build image') {
steps {
script {
app = docker.build("${DOCKER_IMAGE}")
}
}
}
stage('Test image') {
steps {
script {
app.inside {
sh 'npm ci'
sh 'npm test'
}
}
}
}
stage('Push image') {
steps {
script {
docker.withRegistry('https://registry.hub.docker.com', 'jinseon901') {
app.push("${BUILD_NUMBER}")
app.push('latest')
}
}
}
}
stage('Deploy to GKE') {
//main 브랜치만 배포
when {
branch 'main'
}
steps {
sh """
sed -i 's#${DOCKER_IMAGE}:[^[:space:]]*#${DOCKER_IMAGE}:${BUILD_NUMBER}#g' k8s/deployment.yaml
"""
step([
$class: 'KubernetesEngineBuilder',
projectId: env.PROJECT_ID,
clusterName: env.CLUSTER_NAME,
location: env.LOCATION,
credentialsId: env.CREDENTIALS_ID,
manifestPattern: 'k8s/',
verifyDeployments: true
])
}
}
}
}