forked from javahometech/myweb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kubernetes-ci-cd
43 lines (39 loc) · 1.3 KB
/
kubernetes-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
node{
def pom = readMavenPom file: 'pom.xml'
def mvnVersion = pom.version
stage('SCM Checkout'){
git branch: 'master',
credentialsId: 'javahometech',
url: 'https://github.com/javahometech/myweb'
}
stage('Maven Build'){
def mvnHome = tool name: 'maven3', type: 'maven'
sh "${mvnHome}/bin/mvn clean package"
sh 'mv target/myweb*.war target/myweb.war'
}
stage('Build Docker Image'){
sh "docker build -t kammana/myweb:${mvnVersion} ."
}
stage('Upload To DockerHub'){
sh "docker login -u kammana -p Cloud@1234"
sh "docker push kammana/myweb:${mvnVersion}"
}
stage('Deploy to Dev'){
sshagent(['tomcat-dev']) {
def dockeRm = "ssh ec2-user@172.31.14.131 docker rm -f myweb"
def dockeRun = "ssh ec2-user@172.31.14.131 docker run -d -p 80:8080 --name myweb kammana/myweb:${mvnVersion}"
sh "${dockeRm}"
sh "${dockeRun}"
}
}
stage('Deploy to Kubernetes'){
sshagent(['kubernetes-client']) {
sh "scp -o StrictHostKeyChecking=no deployments.yml ec2-user@172.31.23.138:/home/ec2-user/"
try{
sh "ssh ec2-user@172.31.23.138 kubectl create -f /home/ec2-user/deployments.yml"
}catch(ex){
sh "ssh ec2-user@172.31.23.138 kubectl apply -f /home/ec2-user/deployments.yml"
}
}
}
}