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
Aug 13, 2019
1 parent
5db9b02
commit 56819a6
Showing
1 changed file
with
44 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,44 @@ | ||
node('master'){ | ||
// Add maven to path | ||
env.PATH = "/opt/maven3/bin/:$PATH" | ||
|
||
stage('Git Clone/Pull'){ | ||
git branch: 'dev', | ||
url: 'https://github.com/javahometech/my-app' | ||
} | ||
|
||
stage('Build Docker Image'){ | ||
sh "mvn clean package" | ||
sh "mv target/*.war target/myweb.war" | ||
sh "docker build -t kammana/my-app:1.0 ." | ||
} | ||
|
||
stage('Push Image'){ | ||
withCredentials([string(credentialsId: 'docker-hub', variable: 'dockerHubPwd')]) { | ||
sh "docker login -u kammana -p ${dockerHubPwd}" | ||
} | ||
sh "docker push kammana/my-app:1.0" | ||
} | ||
|
||
stage('Delete Old Container'){ | ||
sshagent (credentials: ['dev-docker']) { | ||
try{ | ||
def dockrRm = "docker rm -f my-app" | ||
def dockrRmImage = "docker rmi kammana/my-app:1.0" | ||
sh "ssh -o StrictHostKeyChecking=no [email protected] ${dockrRm} " | ||
sh "ssh -o StrictHostKeyChecking=no [email protected] ${dockrRmImage} " | ||
}catch(e){ | ||
echo "container my-app not found" | ||
} | ||
} | ||
|
||
} | ||
|
||
stage('Deploy On Dev'){ | ||
sshagent (credentials: ['dev-docker']) { | ||
def dockerRun = "docker run -d -p 8080:8080 --name=my-app kammana/my-app:1.0" | ||
sh "ssh -o StrictHostKeyChecking=no [email protected] ${dockerRun} " | ||
} | ||
} | ||
|
||
} |