-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile-kubernetes
99 lines (99 loc) · 2.58 KB
/
Jenkinsfile-kubernetes
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
pipeline {
agent {
kubernetes {
yaml '''
apiVersion: v1
kind: Pod
spec:
containers:
- name: maven
image: maven:3.8.6-openjdk-8
command:
- sleep
args:
- infinity
- name: git
image: alpine/git
command:
- sleep
args:
- infinity
- name: kaniko
image: gcr.io/kaniko-project/executor:debug
command:
- sleep
args:
- infinity
volumeMounts:
- name: registry-credentials
mountPath: /kaniko/.docker
volumes:
- name: registry-credentials
secret:
secretName: regcred
items:
- key: .dockerconfigjson
path: config.json
'''
}
}
triggers {
//pollSCM('* * * * *')
githubPush()
}
stages {
stage('Checkout') {
steps {
container('maven') {
git branch: 'main', url: 'https://github.com/dbfan24/source-maven-java-spring-hello-webapp.git'
}
}
}
stage('Build') {
steps {
container('maven') {
sh 'mvn clean package -DskipTests=true'
}
}
}
stage('Test') {
steps {
container('maven') {
sh 'mvn test'
}
}
}
stage('Build & Tag & Push Docker Image') {
steps {
container('kaniko') {
sh 'executor --context=dir:///home/jenkins/agent/workspace/kube_pipeline/ --destination=dbfan24/kaniko_test:$BUILD_NUMBER --destination=dbfan24/kaniko_test:latest'
}
}
}
stage('Update K8s Manifests & Push') {
environment {
githubUser = 'than.kim' //Ryan Jang
githubEmail = '[email protected]' //[email protected]
githubId = 'dbfan24' //c1t1d0s7
githubRepo = 'deploy-kube-object' //jenkins-kube-deploy
githubURL = "https://github.com/${githubId}/${githubRepo}.git"
dockerhubId = 'dbfan24' //c1t1d0s7
dockerhubRepo = 'kaniko_test' //hello-world
}
steps {
container('git') {
git branch: 'main', credentialsId: 'github-credential', url: "${githubURL}"
sh "git config --global --add safe.directory ${workspace}"
sh "git config --global user.name ${githubUser}"
sh "git config --global user.email ${githubEmail}"
sh 'sed -i "s/image:.*/image: ${dockerhubId}\\/${dockerhubRepo}:${BUILD_NUMBER}/g" deployment.yaml'
sh 'git add deployment.yaml'
sh 'git commit -m "Jenkins Build Number - ${BUILD_NUMBER}"'
withCredentials([gitUsernamePassword(credentialsId: 'github-credential', gitToolName: 'Default')]) {
sh 'git push --set-upstream origin main'
}
}
}
}
}
}