forked from srinivas1987devops/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 [email protected] docker rm -f myweb"
def dockeRun = "ssh [email protected] 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 [email protected]:/home/ec2-user/"
try{
sh "ssh [email protected] kubectl create -f /home/ec2-user/deployments.yml"
}catch(ex){
sh "ssh [email protected] kubectl apply -f /home/ec2-user/deployments.yml"
}
}
}
}