Skip to content

Commit

Permalink
Create JenkinsPiplelineScriptDockerSwarm_Private_Repo
Browse files Browse the repository at this point in the history
  • Loading branch information
devopstrainingbanglore authored Nov 15, 2019
1 parent 0f15cc9 commit 631cc75
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions JenkinsPiplelineScriptDockerSwarm_Private_Repo
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
node{

def buildNumber = BUILD_NUMBER

stage("Git CheckOut"){
git url: 'https://github.com/MithunTechnologiesDevOps/java-web-app-docker.git',branch: 'master'
}

stage(" Maven Clean Package"){
def mavenHome = tool name: "Maven-3.6.2", type: "maven"
def mavenCMD = "${mavenHome}/bin/mvn"
sh "${mavenCMD} clean package"
}

stage("Build Dokcer Image") {
sh "docker build -t 172.31.1.204:8083/java-web-app:${buildNumber} ."
}


stage("Docker Push"){

withCredentials([string(credentialsId: 'Docker_Repo_Pwd', variable: 'Docker_Repo_Pwd')]) {
sh "docker login -u admin -p ${Docker_Repo_Pwd} 172.31.1.204:8083"
}

sh "docker push 172.31.1.204:8083/java-web-app:${buildNumber}"
}

stage("Deploy to docker swarm cluster"){
sshagent(['Docker_Swarm_Manager_Dev']) {
sh 'ssh -o StrictHostKeyChecking=no [email protected] docker service rm javawebapp || true'
withCredentials([string(credentialsId: 'Docker_Repo_Pwd', variable: 'Docker_Repo_Pwd')]) {

sh "ssh -o StrictHostKeyChecking=no [email protected] docker login -u admin -p ${Docker_Repo_Pwd} 172.31.1.204:8083"
}
sh "ssh [email protected] docker service create --name javawebapp -p 7070:8080 --replicas 2 --with-registry-auth 172.31.1.204:8083/java-web-app:${buildNumber}"
}
}

}

0 comments on commit 631cc75

Please sign in to comment.