forked from srinivas1987devops/myweb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
javahometech
authored
Jan 20, 2019
1 parent
a0072c6
commit 4aa12fe
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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" | ||
} | ||
} | ||
} | ||
} | ||
|