Skip to content

Commit

Permalink
Create jenkins-oct-19-pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
javahometech authored Oct 19, 2019
1 parent e9ac60b commit ccf6174
Showing 1 changed file with 73 additions and 0 deletions.
73 changes: 73 additions & 0 deletions jenkins-oct-19-pipeline
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
}

0 comments on commit ccf6174

Please sign in to comment.