forked from javahometech/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
Oct 19, 2019
1 parent
e9ac60b
commit ccf6174
Showing
1 changed file
with
73 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,73 @@ | ||
pipeline{ | ||
agent any | ||
|
||
environment { | ||
PATH = "${PATH}:${getMavenPath()}" | ||
DOCKER_TAG = "${getLatestCommitId()}" | ||
NEXUS_HOST = "172.31.45.145:8083" | ||
DEV_IP = "172.31.6.150" | ||
} | ||
stages{ | ||
stage('SCM - Checkout'){ | ||
steps{ | ||
git url: 'https://github.com/javahometech/myweb' | ||
|
||
} | ||
} | ||
|
||
stage('Maven - Build'){ | ||
steps{ | ||
sh "mvn clean package" | ||
} | ||
} | ||
|
||
stage('Docker - Build'){ | ||
steps{ | ||
withCredentials([string(credentialsId: 'nexus-docker', variable: 'nexusPwd')]) { | ||
sh "docker login -u admin -p ${nexusPwd} ${NEXUS_HOST}" | ||
} | ||
|
||
sh "docker build . -t ${NEXUS_HOST}/myweb:${DOCKER_TAG} " | ||
} | ||
} | ||
|
||
stage('Docker - Push'){ | ||
steps{ | ||
sh "docker push ${NEXUS_HOST}/myweb:${DOCKER_TAG}" | ||
} | ||
} | ||
|
||
stage('Docker - Deploy - Dev'){ | ||
steps{ | ||
sh returnStatus: true, script: "ssh ec2-user@${DEV_IP} docker rm -f myweb" | ||
withCredentials([string(credentialsId: 'nexus-docker', variable: 'nexusPwd')]) { | ||
sh returnStatus: true, script: "ssh ec2-user@${DEV_IP} docker login -u admin -p ${nexusPwd} ${NEXUS_HOST}" | ||
} | ||
|
||
sh returnStatus: true, script: 'ssh ec2-user@${DEV_IP} docker rmi $(docker images | grep 172.31.45.145:8083/myweb | awk \'{print $3}\')' | ||
sh "ssh ec2-user@${DEV_IP} docker run -d -p 8080:8080 --name=myweb ${NEXUS_HOST}/myweb:${DOCKER_TAG}" | ||
} | ||
} | ||
|
||
} | ||
post{ | ||
always{ | ||
mail body: """Hi Dev Team, | ||
${env.BUILD_URL} | ||
This Job ran | ||
|
||
Thanks, | ||
DevOps Team""", subject: "${env.JOB_NAME} Ran", to: '[email protected]' | ||
} | ||
} | ||
} | ||
|
||
def getMavenPath(){ | ||
def mvnHome = tool name: 'maven-3', type: 'maven' | ||
return "${mvnHome}/bin" | ||
} | ||
|
||
def getLatestCommitId(){ | ||
def commitId = sh returnStdout: true, script: 'git rev-parse HEAD' | ||
return commitId | ||
} |