forked from javahometech/my-app
-
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
Dec 5, 2018
1 parent
4f4e0e6
commit 50d6579
Showing
1 changed file
with
41 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,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}" | ||
|
||
} | ||
} | ||
} | ||
} |