-
Notifications
You must be signed in to change notification settings - Fork 4.1k
/
k8s-ci-cd
47 lines (45 loc) · 1.24 KB
/
k8s-ci-cd
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
pipeline{
agent any
tools {
maven 'maven3'
}
stages{
stage('SCM Checkout'){
steps{
git 'https://github.com/javahometech/myweb'
}
}
stage('Maven Build'){
steps{
sh "mvn clean package"
}
}
stage('Docker Build'){
steps{
sh "docker build . -t 13.233.112.225:8083/myweb:${dockerTag()}"
}
}
stage('Docker Push Nexus'){
steps{
withCredentials([string(credentialsId: 'nexuss3', variable: 'nexusPwd')]) {
sh "docker login -u admin -p ${nexusPwd} 13.233.112.225:8083"
sh "docker push 13.233.112.225:8083/myweb:${dockerTag()}"
}
}
}
stage('Deploy k8s'){
steps{
sh """
VERSION=${dockerTag()}
sed -i "s/commit_hash/\$VERSION/g" k8s/deployment.yml
"""
kubernetesDeploy configs: 'k8s/*.yml',
kubeconfigId: 'kubernetess-cluster'
}
}
}
}
def dockerTag(){
def commitId = sh returnStdout: true, script: 'git rev-parse --short HEAD'
return commitId
}