Skip to content

Commit 06af26b

Browse files
authored
Update Jenkinsfile
1 parent c5342bd commit 06af26b

1 file changed

Lines changed: 29 additions & 39 deletions

File tree

Jenkinsfile

Lines changed: 29 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,30 @@
1-
node{
2-
3-
stage('SCM Checkout'){
4-
git url: 'https://github.com/MithunTechnologiesDevOps/java-web-app-docker.git',branch: 'master'
5-
}
6-
7-
stage(" Maven Clean Package"){
8-
def mavenHome = tool name: "Maven-3.5.6", type: "maven"
9-
def mavenCMD = "${mavenHome}/bin/mvn"
10-
sh "${mavenCMD} clean package"
11-
12-
}
13-
14-
15-
stage('Build Docker Image'){
16-
sh 'docker build -t dockerhandson/java-web-app .'
17-
}
18-
19-
stage('Push Docker Image'){
20-
withCredentials([string(credentialsId: 'Docker_Hub_Pwd', variable: 'Docker_Hub_Pwd')]) {
21-
sh "docker login -u dockerhandson -p ${Docker_Hub_Pwd}"
22-
}
23-
sh 'docker push dockerhandson/java-web-app'
24-
}
25-
26-
stage('Run Docker Image In Dev Server'){
27-
28-
def dockerRun = ' docker run -d -p 8080:8080 --name java-web-app dockerhandson/java-web-app'
29-
30-
sshagent(['DOCKER_SERVER']) {
31-
sh 'ssh -o StrictHostKeyChecking=no ubuntu@172.31.20.72 docker stop java-web-app || true'
32-
sh 'ssh ubuntu@172.31.20.72 docker rm java-web-app || true'
33-
sh 'ssh ubuntu@172.31.20.72 docker rmi -f $(docker images -q) || true'
34-
sh "ssh ubuntu@172.31.20.72 ${dockerRun}"
35-
}
36-
37-
}
38-
39-
1+
node {
2+
def mavenHome = tool name : "maven3.8.6"
3+
def buildnumber = BUILD_NUMBER
4+
stage('CheckOut_Code') {
5+
git credentialsId: '4735d413-1ac8-4b65-867c-23e03607e5d1', url: 'https://github.com/Deep0511/java-web-app-docker.git'
6+
}
7+
stage ('Build') {
8+
sh "${mavenHome}/bin/mvn clean package"
9+
}
10+
stage ('Build-Docker-Image') {
11+
sh "docker build -t 623158369342.dkr.ecr.ap-south-1.amazonaws.com/java-web-application:${buildnumber} ."
4012
}
13+
stage ('Login to ECR') {
14+
sh "aws ecr get-login-password --region ap-south-1 | docker login --username AWS --password-stdin 623158369342.dkr.ecr.ap-south-1.amazonaws.com"
15+
}
16+
stage ('Push To ECR') {
17+
sh "docker push 623158369342.dkr.ecr.ap-south-1.amazonaws.com/java-web-application:${buildnumber}"
18+
}
19+
// Remove local image in Jenkins Server
20+
stage ("Remove Local Image") {
21+
sh "docker rmi -f 623158369342.dkr.ecr.ap-south-1.amazonaws.com/java-web-application:${buildnumber}"
22+
}
23+
stage("Deploy to ") {
24+
sshagent(['ssh-agent']) {
25+
sh "scp -o Strict HostKeyChecking=no docker-compose.yml ubuntu@172.31.38.68:/home/ubuntu"
26+
sh "ssh Strict HostKeyChecking=no ubuntu@172.31.38.68 docker-compose up -d"
27+
}
28+
}
29+
}
30+

0 commit comments

Comments
 (0)