-
Notifications
You must be signed in to change notification settings - Fork 2
/
Jenkinsfile-3-kubernetes-deploy
81 lines (73 loc) · 2.48 KB
/
Jenkinsfile-3-kubernetes-deploy
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
pipeline {
agent any
options {
disableConcurrentBuilds()
ansiColor('xterm')
}
environment {
JAVA_TOOL_OPTIONS="-Djansi.force=true -Duser.home=${WORKSPACE}"
GIT_SHA_SHORT="${env.GIT_COMMIT.take(7)}"
GIT_BRANCH_SAFE="${env.GIT_BRANCH.minus('origin/').replace('/', '-')}"
APP_NAME="java-meetup-quarkus"
APP_IMAGE="jwnmulder/${env.APP_NAME}:1.0-${env.GIT_BRANCH_SAFE}.${env.GIT_SHA_SHORT}"
KUBE_NAMESPACE="java-meetup"
KUBE_NAME_PREFIX="${env.GIT_BRANCH_SAFE}"
KUBE_DEPLOY_NAME="${env.KUBE_NAME_PREFIX}-${env.APP_NAME}"
}
stages {
stage ('checkout') {
steps {
checkout scm
}
}
stage ('build') {
agent {
docker reuseNode: true, image: "maven:3.6.2-jdk-11", args: "-e MAVEN_CONFIG=${WORKSPACE}/.m2"
}
steps {
sh "mvn clean package"
junit '**/target/surefire-reports/*.xml'
}
}
stage('docker build') {
steps {
script {
def image = docker.build(env.APP_IMAGE, "-f src/main/docker/Dockerfile.jvm --pull .")
docker.withRegistry("https://registry.hub.docker.com", "docker-hub") {
image.push()
}
}
}
}
stage('prepare deploy') {
agent {
docker reuseNode: true, image: "place1/kube-tools:2019.10.13", args: "--entrypoint=''"
}
steps {
dir('deploy') {
sh """
> kustomization.yaml
kustomize edit add base overlays/jenkins-with-nodeport
kustomize edit set nameprefix '${env.KUBE_NAME_PREFIX}-'
kustomize edit add label 'app.kubernetes.io/part-of:${env.KUBE_DEPLOY_NAME}'
kustomize edit set image '${env.APP_IMAGE}'
kustomize build > generated.yaml
"""
}
}
}
stage('deploy to test') {
agent {
docker reuseNode: true, image: "place1/kube-tools:2019.10.13", args: "--entrypoint=''"
}
steps {
withCredentials([file(credentialsId: "kubectl-config", variable: 'KUBECONFIG')]) {
sh "kubectl -n ${env.KUBE_NAMESPACE} apply -f deploy/generated.yaml --prune -l 'app.kubernetes.io/part-of=${env.KUBE_DEPLOY_NAME}'"
sh "kubectl -n ${env.KUBE_NAMESPACE} rollout status --watch deployment ${env.KUBE_DEPLOY_NAME}"
sh "kubectl -n ${env.KUBE_NAMESPACE} get deployments,ingress,service -o wide"
sh "kubectl -n ${env.KUBE_NAMESPACE} logs deployment/${KUBE_DEPLOY_NAME} -c web"
}
}
}
}
}