Skip to content

Commit

Permalink
Create docker-swarm-ci-cd
Browse files Browse the repository at this point in the history
  • Loading branch information
javahometech authored Dec 5, 2018
1 parent 4f4e0e6 commit 50d6579
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions docker-swarm-ci-cd
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
node{
def pom = readMavenPom file: 'pom.xml'
def version = pom.version
def nexus_tag = "172.31.24.222:8083/myweb:${version}"
def mvnHome = tool name: 'maven-3', type: 'maven'
def mvn = "${mvnHome}/bin/mvn"
stage('SCM Checkout'){
git 'https://github.com/javahometech/my-app'
}
stage('Maven Build'){
sh "${mvn} clean package"
sh 'mv target/myweb*.war target/myweb.war'
}

stage('Docker Build'){

sh "docker build -t ${nexus_tag} ."
}

stage('Push to Nexus'){
sh "docker login 172.31.24.222:8083 -u admin -p admin123"
sh "docker push ${nexus_tag}"
}

stage('Deploy to swarm'){
try{
def service = "docker service create -d -p 90:8080 --replicas=7 --name=myweb ${nexus_tag}"
sshagent (credentials: ['docker-swarm-manager']) {
def svs = "[email protected] ${service}"
sh "ssh -o StrictHostKeyChecking=no ${svs}"
}
}catch(e){
def service = "docker service update --image=${nexus_tag} myweb"
sshagent (credentials: ['docker-swarm-manager']) {
def svs = "[email protected] ${service}"
sh "ssh -o StrictHostKeyChecking=no ${svs}"

}
}
}
}

0 comments on commit 50d6579

Please sign in to comment.