-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJenkinsfile
98 lines (93 loc) · 3.02 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
pipeline {
agent none
options { skipDefaultCheckout(true) }
environment {
PROJECT_ID = 'opensource-team'
CLUSTER_NAME = 'k8s'
LOCATION = 'asia-northeast3-a'
CREDENTIALS_ID = '1ae4e1a9-f5e1-4ec8-907d-aef2248d041e'
}
stages {
stage('Checkout repository') {
agent any
steps {
checkout scm
}
}
stage('Secret.yml download') {
agent any
steps {
withCredentials([file(credentialsId: 'db-credential', variable: 'dbConfigFile')]) {
script {
sh 'chmod 755 src/main/resources/application-db.yml'
sh 'cp $dbConfigFile src/main/resources/application-db.yml'
}
}
}
}
stage('Build and test') {
agent {
docker {
image 'gradle:7.6.3-jdk17-alpine'
args '-v /root/.m2:/root/.m2'
}
}
steps {
sh 'gradle clean build -x test'
}
}
stage('Docker build') {
agent any
when {
branch 'main'
}
steps {
script {
myapp = docker.build("choiyoorim/blog:${env.BUILD_ID}")
}
}
}
stage('Test Docker build') {
agent any
when {
branch 'develop'
}
steps {
script {
myapp = docker.build("choiyoorim/testblog:${env.BUILD_ID}")
}
}
}
stage('Docker push image') {
agent any
steps {
script {
docker.withRegistry('https://registry.hub.docker.com', 'dockerhub') {
myapp.push("latest")
myapp.push("${env.BUILD_ID}")
}
}
}
}
stage('Docker run') {
agent any
when {
branch 'main'
}
steps{
sh "sed -i 's/blog:latest/blog:${env.BUILD_ID}/g' Deployment.yaml"
step([$class: 'KubernetesEngineBuilder', projectId: env.PROJECT_ID, clusterName: env.CLUSTER_NAME, location: env.LOCATION, manifestPattern: 'Deployment.yaml', credentialsId: env.CREDENTIALS_ID, verifyDeployments: true])
}
}
stage('Test Docker run') {
agent any
when {
branch 'develop'
}
steps{
sh "sed -i 's/testblog:latest/testblog:${env.BUILD_ID}/g' TestDeployment.yaml"
step([$class: 'KubernetesEngineBuilder', projectId: env.PROJECT_ID, clusterName: env.CLUSTER_NAME, location: env.LOCATION, manifestPattern: 'TestDeployment.yaml', credentialsId: env.CREDENTIALS_ID, verifyDeployments: true])
}
}
}
}